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
I know this answer come too late but I have seen in enough code you can use the sudo option -i
so:
- name: source bashrc
shell: sudo -iu {{ansible_user_id}} [the actual command you want run]
As said in the documentation
The -i (simulate initial login) option runs the shell specified by the password database entry of the target user as a login shell. This means that login-specific
resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution via the shell's -c option.
If no command is specified, an interactive shell is executed. sudo attempts to change to that user's home directory before running the shell. It also initializes
the environment to a minimal set of variables, similar to what is present when a user logs in. The Command environment section below documents in detail how the -i
option affects the environment in which a command is run.