0

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 new PATH: /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 PATHs /sbin:/bin:/usr/sbin:/usr/bin and /opt/conda/condabin:/usr/local/bin:/usr/bin respectively.

Simon Rose
  • 381
  • 5
  • 11
  • If you are explicitly installing something somewhere then explicitly run it from there: `command: /usr/sbin/my_binary` or `command: my_binary` and `chdir: /usr/sbin` or `command: my_binary` and https://stackoverflow.com/a/46937169/2123530. – β.εηοιτ.βε Apr 03 '23 at 08:14

1 Answers1

-1

Ugh, after struggling with this for days, 5 minutes after asking it I solved it: a missing become: true when including the role A.

Simon Rose
  • 381
  • 5
  • 11
  • 1
    Since the roles themselves are not included in your question, there is close to no chance the said question is going to help anyone further down the line, and should rather be closed as a typo and possibly deleted. – β.εηοιτ.βε Apr 03 '23 at 08:17