# how to set python interpreter between different roles

**URL:** <https://forum.ansible.com/t/how-to-set-python-interpreter-between-different-roles/30132>\
**Category:** Ansible Project\
**Created:** [April 17, 2019, 9:56am UTC](https://forum.ansible.com/t/how-to-set-python-interpreter-between-different-roles/30132 "2019-04-17T09:56:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christian.tremel](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@christian.tremel](https://forum.ansible.com/u/christian.tremel)\
**Post date:** [April 17, 2019, 9:56am UTC](https://forum.ansible.com/t/how-to-set-python-interpreter-between-different-roles/30132/1 "2019-04-17T09:56:48Z")

</div>

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”

` `

---

<div class="post-metadata">

**Author:** ![christian.tremel](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@christian.tremel](https://forum.ansible.com/u/christian.tremel)\
**Post date:** [April 18, 2019, 7:32am UTC](https://forum.ansible.com/t/how-to-set-python-interpreter-between-different-roles/30132/2 "2019-04-18T07:32:35Z")

</div>

nobody?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 18, 2019, 3:50pm UTC](https://forum.ansible.com/t/how-to-set-python-interpreter-between-different-roles/30132/3 "2019-04-18T15:50:47Z")

</div>

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

roles:  
&nbsp;&nbsp;&nbsp;- name: X  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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.
