Not possible to source .bashrc with Ansible

后端 未结 10 1606
耶瑟儿~
耶瑟儿~ 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 08:45

    I was experiencing this same issue when trying to get virtualenvwrapper to work on an Ubuntu server. I was using Ansible like this:

    - name: Make virtual environment
      shell: source /home/username/.bashrc && makevirtualenv virenvname
      args:
        executable: /bin/bash
    

    but the source command was not working.

    Eventually I discovered that the .bashrc file has a few lines at the top of the file that prevent source from working when called by Ansible:

    # If not running interactively, don't do anything
    case $- in
        *i*) ;;
          *) return;;
    esac
    

    I commented out those lines in .bashrc and everything worked as expected after that.

提交回复
热议问题