ansible

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?


Solution

  • 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.