felix001
felix001

Reputation: 16691

Ansible Python interpreter Issue

Im trying to change the Python interpreter as Im in a virtual environment. But also I will be deploying the venv on a Jenkins server that only has python2. Hence....

# grep python ansible/ansible.cfg
interpreter_python = ./venv/bin/python2

ansible --version | grep "python version"
  python version = 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609]

What am I missing?

Upvotes: 4

Views: 10439

Answers (3)

mikeziminio
mikeziminio

Reputation: 71

Just set the absolute path the to the python interpreter, which should Ansible use on remote hosts in ansible.cfg:

[defaults]
interpreter_python = /usr/bin/python3.12

Of course before that you should install this version of python on remote hosts. If you want to do it with ansible - you can use ansible.builtin.raw module.

Upvotes: 0

Shubham Gorlewar
Shubham Gorlewar

Reputation: 424

Install Ansible with

pip3 installl ansible 

So, it will work with Python 3+.

Upvotes: -1

guzmonne
guzmonne

Reputation: 2540

Check the "Using Python3 on the managed machines with commands and playbooks" section of the Docs. The piece is for python3 but it truly doesn't matter which version of python you end up using. On that article you'll see this quote:

To explicitly configure a Python 3 interpreter, set the ansible_python_interpreter inventory variable at a group or host level to the location of a Python 3 interpreter, such as /usr/bin/python3. The default interpreter path may also be set in ansible.cfg.

So, just set the ansible_python_interpreter at the level that makes sense for your hosts.

Upvotes: 3

Related Questions