bashrc or bash_profile not being sourced

I think this has been discussed before. The documentations says:

“If you want to run a command through the shell (say you are using <, >, |, etc), you actually want the shell module instead. The command module is much more secure as it’s not affected by the user’s environment.”

Implicitly, I read this as if I do use the shell command, I should get the users environment. Is this assumption wrong?

Now I do this, occasionally, in order to include anything from my user profile:

shell: . ~/.bashrc && env > /tmp/env

The use case I have is to install a mule license, which requires MULE_HOME. I could write a two line wrapper, but I’d rather not have more parts than I can get away with. I do as follows:

shell: . ~/.bashrc && ./mule -installLicense {{ mule_user_home }}/mule-ee-license.lic chdir={{ mule_home }}/bin

a few things:

  • you have a hash in ansible_env that shows what the environment is (for user you gathered facts as).
  • ansible doesn’t source .rc files
  • the environment: keyword lets you set env variables for the execution context.