I have observed the following (in my opinion) extremely strange and seemingly inconsistent behaviour when developing molecule tests for an ansible role.
My role (A) depends on another role, B. B runs a task that is also included as a handler (I am not sure if this is relevant). This task uses the command
module to run an executable that is installed by role B which is installed at /usr/sbin
.
When B is included by A as a dependency and runs the given task B as a handler, it runs the executable perfectly well.
For testing purposes, I have added a side-effect stage that re-runs the role A (and hence B as well). However, when this runs it fails to find the executable, causing an issue down the line.
I have attempted to debug this as best as possible (see https://docs.ansible.com/ansible/2.8/dev_guide/debugging.html), and what I have found is that $PATH
is not the same in each of these cases:
- When B runs in the converge stage as a handler, the
PATH
is/sbin:/bin:/usr/sbin:/usr/bin
- When B runs as a task in the side-effect stage, the
PATH
is/opt/conda/condabin:/usr/local/bin:/usr/bin
- If I follow the debug steps above in order to get the
PATH
, (i.e.molecule login --host <hostname>
, etc.) it runs correctly (despite having just failed) with a newPATH
:/opt/conda/condabin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin
If I set the ansible verbosity to its highest, I can see that when running the command in both the successful and failed cases is "the same". So where does it get the PATH
from? What is happening here?
(Note that, as the path shown above suggests, I am using vagrant as my provider, in case that is relevant)
I should further note that if I run the exact commands given by the overly verbose log, then I get the PATH
s /sbin:/bin:/usr/sbin:/usr/bin
and /opt/conda/condabin:/usr/local/bin:/usr/bin
respectively.