Not possible to source .bashrc with Ansible

后端 未结 10 1585
耶瑟儿~
耶瑟儿~ 2020-12-02 08:19

I can ssh to the remote host and do a source /home/username/.bashrc - everything works fine. However if I do:

- name: source bashrc
  sudo: no
          


        
10条回答
  •  时光取名叫无心
    2020-12-02 09:07

    My 2 cents, i circumnavigated the problem sourcing ~/.nvm/nvm.sh into ~/.profile and then using sudo -iu as suggested in another answer.

    Tried on January 2018 vs Ubuntu 16.04.5

    - name: Installing Nvm 
      shell: >
        curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
      args:
        creates: "/home/{{ ansible_user }}/.nvm/nvm.sh"
      tags:
        - nodejs    
    
    - name: Source nvm in ~/.profile
      sudo: yes
      sudo_user: "{{ ansible_user }}"
      lineinfile: >
        dest=~/.profile
        line="source ~/.nvm/nvm.sh"
        create=yes
      tags: 
        - nodejs
      register: output    
    
    - name: Installing node 
      command: sudo -iu {{ ansible_user }} nvm install --lts
      args:
         executable: /bin/bash
      tags:
        - nodejs    
    

提交回复
热议问题