how to set python interpreter between different roles

so i have this play to do some rpm package management. this involves removing the python package from the system. so i install some fallback python package which should be used while the sytem python is not available.
my play consists of three roles, the first two should use the system python and the third should use the fallback python. i have set the “ansible_python_interpreter” var in the third role but for unknown reasons this gest smeared over
to the first two roles, so i get “/usr/bin/ksh: /opt/bin/python: not found.” so how to set the “ansible_python_interpreter” var solely for one role?

the play:

`
root@lpgaixmgmtlx01:/etc/ansible/aix/roles/do_aixtoolbox_migration>cat …/…/deploy_aixtoolbox.yml

  • name: deploy aixtoolbox
    hosts: AIXTESTLPAR01
    gather_facts: false

environment:
PATH: “/opt/bin:/opt/freeware/bin:{{ ansible_env.PATH }}”
SHELL: “/usr/bin/ksh”
LIBPATH: “/opt/lib:/usr/lib:/lib:/opt/freeware/lib”

roles:

  • install_additional_python
  • update_openssl_lpp
  • do_aixtoolbox_migration

`

ansible_python_interpreter is set in role "do_aixtoolbox_migration" but also effects two two other roles.


root@lpgaixmgmtlx01:/etc/ansible/aix/roles/do_aixtoolbox_migration>cat vars/main.yml

ansible_shell_executable: “/usr/bin/ksh”
ansible_shell_interpreter: “/usr/bin/ksh”
ansible_python_interpreter: “/opt/bin/python”

nobody?

First, I would use 'defaults/main.yml' instead of vars, it has lower
precedence, also look into:

roles:
   - name: X
     vars:
         ansible_python_intepreter: /path/x

or set in block inside the role that needs it, which would keep it
from bleeding over.

Role vars/ and defaults/ are meant to be inserted in rest of play, if
you do not want that behaviour, you should use other ways to declare
that variable.