ansible

How to make Ansible read the path variables?


I have a few scripts in my ~/bin that are loaded when I start a shell because this has been included in my $PATH. However, if I have a task in an Ansible playbook that tries to execute one of those scripts, it fails with:

fatal: [node3]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": "nodetool status", "delta": "0:00:00.002779", "end": "2019-12-03 00:17:18.595695", "msg": "non-zero return code", "rc": 127, "start": "2019-12-03 00:17:18.592916", "stderr": "/bin/sh: 1: nodetool: not found", "stderr_lines": ["/bin/sh: 1: nodetool: not found"], "stdout": "", "stdout_lines": []}

In this case the script is ~/bin/nodetool. If I give the absolute path to Ansible it works, so I guess Ansible is not loading $PATH.

How can I force Ansible to load the $PATH environment variables so I can access those scripts without having to provide full path?


Solution

  • I guess your path is set in your .bashrc which is not loaded by ansible when running shell.

    There is a discussion in a closed (won't fix) ticket explaining why this is the case. You need to install those commands globally, or source .bashrc && command, or set the path globally....