Ansible: how to globally set PATH for solaris
I am writing Ansible playbooks to install and install our applications on Solaris servers.
The problem is that the scripts (bash) I need to execute assume that a certain directory is in the PATH, namely /data/bin
- which usually wouldn't be a problem if it wasn't for Ansible ignoring everything .profile
and .bashrc
config.
Now I know that you can specify the environment for tasks shell
using a flag environment
, for example like this:
- shell: printenv
environment:
PATH: /usr/bin:/usr/sbin:/data/bin
This will bring up the correct folder path /data/bin
and the command printenv
will display correctly (or my bash scripts will execute correctly).
But. However, there are two problems:
- First of all, it is very annoying to have to specify the environment over and over again. I know that you can define the environment in some variable of the database and reference file, but you still need to set
environment: ...
for each individual taskshell
. - Secondly, the above example does not allow me to specify the path dynamically, eg. how
PATH: $PATH:/data/bin
- because Ansible does it in a way that doesn't allow it$PATH
, so the command doesn't work disastrously. Therefore, in essence, this will undo any other changes toPATH
.
I am looking for a solution where
- additional entry
PATH
needs to be added only once - additional record
PATH
should not override records added by other tasks
PS I found this nice explanation on how to do this on Linux , but uses /etc/environment
which Solaris does not. ( /etc/profile
Again, ignored by Ansible.)
source to share
try adding -o SendEnv=PATH
in ssh_args
to ansible.cfg . It is required that
- the shell you run ansible in has / data / bin in PATH. Or, nevertheless, it allows you to change the current / local PATH variable.
- the remote machine AcceptEnv is installed correctly.
source to share