Not possible to source .bashrc with Ansible

后端 未结 10 1604
耶瑟儿~
耶瑟儿~ 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:55

    Well I tried the listed answers but those didn't worked for me while installing ruby through rbenv. I had to source below lines from /root/.bash_profile

    PATH=$PATH:$HOME/bin:$HOME/.rbenv/bin:$HOME/.rbenv/plugins/ruby-build/bin
    export PATH
    eval "$(rbenv init -)"
    

    Finally, I came up with this

    - shell: sudo su - root -c 'rbenv install -v {{ ruby_version }}'
    

    One can use this with any command.

    - shell: sudo su - root -c 'your command'
    

提交回复
热议问题