# Set ansible\_python\_interpreter at Task level?

**URL:** <https://forum.ansible.com/t/set-ansible-python-interpreter-at-task-level/29983>\
**Category:** Ansible Project\
**Created:** [March 25, 2019, 7:36pm UTC](https://forum.ansible.com/t/set-ansible-python-interpreter-at-task-level/29983 "2019-03-25T19:36:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 25, 2019, 7:36pm UTC](https://forum.ansible.com/t/set-ansible-python-interpreter-at-task-level/29983/1 "2019-03-25T19:36:50Z")

</div>

Is there a way to do this? I have a playbook with two tasks. The first task uses Yum module (and python 2 interpreter). The next task uses aws\_s3 module (and python3 interpreter), but fails because the playbook is still trying to use python2 interpreter. (the error is: can’t find boto3…)

I tested this by using two separate Playbooks and declaring the appropriate python interpreter at the Playbook level:

- hosts: ec2lin remote\_user: ec2-user become: yes become\_user: root vars: ansible\_python\_interpreter: /usr/bin/python3

Each task worked in a separate playbook. but I would rather use a single playbook for both Tasks.

Is it possible to set the “ansible\_python\_interpreter” at the Task level - With a keyword or variable or something?

Thank You

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [March 25, 2019, 7:51pm UTC](https://forum.ansible.com/t/set-ansible-python-interpreter-at-task-level/29983/2 "2019-03-25T19:51:58Z")

</div>

Yes, just do the same vars directive on the task like you have done on the play, e.g.

`

- name: my task  
ping:  
vars:  
ansible\_python\_interpreter: /usr/bin/python

`

You would have to keep in mind variable precedence [1], task vars do beat play vars but the following will beat task vars

- Vars added with include\_vars:
- Vars/facts added with set\_fact or register
- Extra vars specified by ‘-e’ when Ansible was invoked

[1] - [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 25, 2019, 9:29pm UTC](https://forum.ansible.com/t/set-ansible-python-interpreter-at-task-level/29983/3 "2019-03-25T21:29:12Z")

</div>

Thank you - I did that and it did use the right interpreter, but written this way the play has a new error:

“missing required arguments: bucket, mode”}

This is the new play with the interpreter var:

- name: downlod file from s3 with aws\_s3 module aws\_s3: vars: ansible\_python\_interpreter: /usr/bin/python3 bucket: launch-data object: jre-8u201-linux-x64.tar.gz dest: /home/ec2-user/updater/jre-8u201-linux-x64.tar.gz mode: get

Is my syntax incorrect?

---

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 25, 2019, 9:33pm UTC](https://forum.ansible.com/t/set-ansible-python-interpreter-at-task-level/29983/4 "2019-03-25T21:33:18Z")

</div>

Got it working - I had to put the vars before the module name - thanks for help

---

<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 9, 2019, 2:47pm UTC](https://forum.ansible.com/t/set-ansible-python-interpreter-at-task-level/29983/5 "2019-04-09T14:47:11Z")

</div>

`vars` is a 'task keyword' different from module options, the problem  
was that you mixed both. This is an indentation issue, not order  
(keywords can appear in any order).
