SolidSnake SolidSnake - 5 months ago 49
Bash Question

Ansible shell command `pod2man` not found

I'm trying to install pacaur using a script via Ansible:

curl -s | bash

With the ansible command

ansible -m shell -a "curl -s | bash"

But I get
complaining about
missing. It seems to be a problem with the PATH of ansible command.

Running the command on the machine directly using ssh works correctly.

Here's the output of:
ansible -m all shell -a 'echo $PATH'

localhost | SUCCESS | rc=0 >>
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl| SUCCESS | rc=0 >>


As reported in comments, the problem is that when switching users sudo sanitize PATH (see this ServerFault question for details).

The ad-hoc command to export the local PATH to hosts that I propose seems a bit hacky but it works (it uses the --extra-vars option of ansible command together with Jinja's variable injection)

ansible all -m shell -a "export PATH={{path}}; curl -s | bash" -e path=$PATH

You could also use the {{ lookup('env', 'PATH') }} to forward the PATH.