I am writing Ansible playbooks to setup and install our applications on Solaris servers.
The problem is that the (bash) scripts which I need to execute all assume that a certain directory lies on the PATH, namely /data/bin
- which would normally not be a problem were it not for Ansible ignoring all the .profile
and .bashrc
config.
Now, I know that you can specify the environment for shell
tasks via the environment
flag, for example like this:
- shell: printenv
environment:
PATH: /usr/bin:/usr/sbin:/data/bin
This will properly path the /data/bin
folder, and the printenv
command will correctly display (or my bash scripts would correctly run).
But. There are two problems however:
- 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 playbook base file variable and the reference that, but you still have to set
environment: ...
on every singleshell
task. - Secondly, the above example does not allow me to specify the path dynamically, e.g. as
PATH: $PATH:/data/bin
- because Ansible executes this in a way which does not resolve$PATH
, thus the command fails catastrophically. So essentially this will override any other changes toPATH
.
I am looking for a solution where
- the additional
PATH
entry should only be added once - the additional
PATH
entry should not override entries added by other tasks
P.S. I found this nice explanation on how to do this on Linux, but it makes use of /etc/environment
which does not exist on Solaris. (And /etc/profile
is once again ignored by Ansible.)