Reputation: 54603
Ansible expects python 2. On my system (Arch Linux), "python" is Python 3, so I have to pass -e "ansible_python_interpreter=/usr/bin/python2"
with every command.
ansible-playbook my-playbook.yml -e "ansible_python_interpreter=/usr/bin/python2"
Is there a away to set ansible_python_interpreter
globally on my system, so I don't have to pass it to every command? I don't want to add it to my playbooks, as not all systems that runs the playbook has a setup similar to mine.
Upvotes: 31
Views: 42670
Reputation: 555
For who want use local activated virtualenv python interpreter
in inventory
file set
[local]
localhost ansible_python_interpreter=python
Upvotes: 6
Reputation: 3254
Well you can set in three ways
ansible_python_interpreter=/usr/bin/python2
this will set it per hostansible_python_interpreter: "/usr/bin/python2"
this will set it per hostgroup_vars/all
(you may need to create the directory group_vars
and the file all
) as ansible_python_interpreter: "/usr/bin/python2"
Hope that helps
Upvotes: 38
Reputation: 6754
I opted to use Ansible's ability to source inventory from a directory. In this manner I could define the ansible_python_interpreter
for localhost only for the local machine
inventory_dir/local
[local]
localhost ansible_python_interpreter="/path/to/alternate/bin/python"
And then just use the directory as you would an inventory file.
ansible-playbook -i inventory_dir playbook.yml
Upvotes: 6