C. Dodds
C. Dodds

Reputation: 345

Configuring ansible to use python3 on remote targets

I've been looking into attempting to get ansible to use python3 on remote targets, in order to run playbooks against them, however, simply running a playbook against a target with python3 installed fails with the error message:

"/bin/sh: 1: /usr/bin/python: not found\r\n"

Looking for answers to this online only seem to discuss configuring ansible on the host to use python3 rather than the remote. Is it possible to configure the remote to use python3 rather than 2?

Upvotes: 9

Views: 5892

Answers (2)

larsks
larsks

Reputation: 311456

You can set the ansible_python_interpreter variable to tell Ansible which version of Python to use. You can set this globally, as C. Dodds has suggested in their answer, but it generally makes more sense to set this as a per-host inventory variable. E.g., using a YAML inventory:

all:
  hosts:
    myhost:
      ansible_python_interpreter: /usr/bin/python3

Or using an ini-style inventory:

myhost ansible_python_interpreter=/usr/bin/python3

And of course you can set this per-hostgroup if you have several hosts that require the same configuration.

This is discussed in the Ansible documentation.

Upvotes: 10

C. Dodds
C. Dodds

Reputation: 345

Adding the argument "-e 'ansible_python_interpreter=/usr/bin/python3'" was the solution to this:

ansible-playbook sample-playbook.yml -e 'ansible_python_interpreter=/usr/bin/python3'

Upvotes: 4

Related Questions