can anybody tell me whether the ~/.bashrc of a become_user is being read on TASK execution, so you could rely on aliases, environment variables or PATH to be effective?
can anybody tell me whether the ~/.bashrc of a become_user is being read on TASK execution, so you could rely on aliases, environment variables or PATH to be effective?
As far as know it is not being read. And I doubt that is a good idea if the goal is idempotence.
Regards
Racke
become_user normally uses sudo, which does not set $HOME or read
.bashrc unless the "sudo -i" options are used. Read "man sudo" for
more understanding.
ok, thx
But doesn’t reading of .bashrc and other bash files depend on the Ansible module that is used, and whether the module executes inside a bash shell?
E.g., module ‘shell’ uses the bash shell unless some other shell is configured explicitly. Thus, one can execute remote with ‘shell’ commands with the same settings as in interactive login.
BR,
Roland
I was not thinking about shell module tbh.
Still, do I understand you correctly that you mean something like
… .bashrc may not be read for most of Ansible modules but it is read for shell and maybe command module?
I mean .bashrc is only read when the used ansible module uses bash. The become_user functionality - that is done before the module execution - does not use bash (as others already answered above).
The command module executes the provided command as such and shell uses a shell (normally bash) to execute the command.
Only, .bashrc isn’t run by the shell module even if bash is used. Testing by adding
export BASHRC_RAN=“# bashrc ran”
to .bashrc and running the shell module to
echo $BASHRC_RAN
bears this out.
Ansible executes in 'batch mode' aka non-interactive, bash normally
does not execute .bashrc in this case (it can be setup to do so, but
most distros default to not do so)