pkaramol
pkaramol

Reputation: 19372

Ansible: Change python interpeter when delegating to

I am running some plays on host A.

There are some other plays that need to run on host B (Ubuntu 16.04) that however ships only with python3, therefore the following task

- name: db_config -> Create MY database
  mysql_db:
    ...create some db
  delegate_to: "{{ ec2_instance_ip }}"

fails with:

failed: [localhost -> 33.99.123.88] => {"changed": false, "module_stderr": "Shared connection to 33.99.123.88 closed.\r\n", "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", "msg": "MODULE FAILURE", "rc": 127}

How can I change python interpeter only for the delegated tasks, as the one above?

Upvotes: 3

Views: 3593

Answers (1)

techraf
techraf

Reputation: 68559

Simply add ansible_python_interpreter to the task:

- name: db_config -> Create MY database
  mysql_db:
    ...create some db
  delegate_to: "{{ ec2_instance_ip }}"
  vars:
    ansible_python_interpreter: /path/to/python

Upvotes: 11

Related Questions