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
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'