Need to source .bash_profile on target system

Hi,

I’m new to ansible and I’m trying to get ansible to source the .bash_profile of the user on the target system. We set many environment variables there in order to run a multitude of scripts. I know that ansible doesn’t support this. Any thoughts on how I can force ansible to source this file?

Thanks!

bob

Just curious: Were you able to figure a way around this??

Once I had to do something similar and the workaround I used was a
command action calling bash with the -l option, e.g.:

    $ ansible server -m command -a "bash -l -c 'env'"

Will print all existent variables, and the -l (makes bash start as a
login shell) forces it to read the .bash_profile (and I also think it
forces reading the .bashrc file too).

I ended moving all environment variables to files in /etc/profile.d
that are sourced by the shell even without the -l or -i options.

Hi,

Even i am trying to source the bashrc file on my target system.
Ansible runs successfully without errors but doesn’t source the file.
Below is my task:

  • name: source bashrc file
    shell: source ~/.bashrc
    args:
    executable: /bin/bash

Didn’t really find that executable arg helping me out.
Any other way around??
Kindly help.

Thanks in advance
Mona G

tis 2017-01-10 klockan 21:59 -0800 skrev Mona Gopal:

Even i am trying to source the bashrc file on my target system.
Ansible runs successfully without errors but doesn't source the file.
Below is my task:

- name: source bashrc file
shell: source ~/.bashrc
args:
executable: /bin/bash

The problem here isn't that Ansible isn't sourcing the file. The
problem is that Ansible isn't sourcing it in a helpful way.

Defined environment variables only take affect in the current process
and its child processes. It doesn't have any affect on parent nor
sibling processes.

Hence, what is happening here is that Ansible is starting a new shell
processes which sources your ~/.bashrc. Right afterwards the shell
processes is exited, and Ansible forgets all about its environment.

Is it an alternative to instead explicitly define the needed
environment variables in the playbook?

https://docs.ansible.com/ansible/playbooks_environment.html

// Andreas