Cannot source ~ / .bashrc file with available

I have a list of aliases in a .bash_aliases file that is being copied to remote servers with ansible playbook . The file is copied to the destination, but .bashrc (which, in turn, loads the .bash_aliases file) does not receive the load using the next available task.

I tried to provide an executable argument

  - name: source the .bashrc file shell: source ~/.bashrc args: executables: "/bin/bash" 

No argument

  - name: source the .bashrc file shell: source ~/.bashrc 

With crude module

  - name: source the .bashrc file raw: source ~/.bashrc 

With a command module - name: source .bashrc file command: source ~ / .bashrc

Nothing works!!! Any help

+8
bash ansible ansible-playbook
source share
2 answers

After reviewing your comments, you stated that you are trying to create aliases, not for a specific session. Why not create these aliases inside /etc/profile.d on machines for which you need these specific aliases, and not for the user?

Also, from another post that came up when I launched a Google search on Ansible specificics, since I am not an Ansible expert ... It is not possible to transfer the .bashrc source using Ansible (thanks to @chucksmash for the link)

"Steve Midgley

You have two options for using a source with accessibility. One with the command "shell:" and / bin / sh (the default is the default). The "source" is called ".". in / bin / sh. Thus, your team will:

 -name: source bashrc sudo: no shell: . /home/username/.bashrc && [the actual command you want run] 

Note that you need to run the command after searching for .bashrc b / c, each ssh session is different - each ansible command is run in a separate ssh transaction.

The second option is to force Ansible shell to use bash, and then you can use the "source" command: \

 name: source bashrc sudo: no shell: source /home/username/.bashrc && [the actual command you want run] args: executable: /bin/bash 

Finally, I want to note that you might want to actually specify "/ etc / profile" if you are on Ubuntu or similar, which more closely mimics a local login. "

+4
source share

If you expect the variables set in one Bash instance to be visible in other Bash instances, or in the Ansible instance that ran this Bash script, there is no way to do this; this is inherent in the Unix process model.

What you can do is set a variable and then run any tool you need to set this value.

 bash -c 'var="value" /path/to/other/tool' 

This can be arbitrarily complex, although you are probably better off creating a separate external script if the task you need to complete may require something more than the most trivial debugging.

0
source share

All Articles