# Trying ansible 2.4/ py3 as tech preview caling python3 /usr/local/bin/ansible-playbook but this results in 'you are running Python 2.x'

**URL:** <https://forum.ansible.com/t/trying-ansible-2-4-py3-as-tech-preview-caling-python3-usr-local-bin-ansible-playbook-but-this-results-in-you-are-running-python-2-x/25713>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [October 10, 2017, 3:27pm UTC](https://forum.ansible.com/t/trying-ansible-2-4-py3-as-tech-preview-caling-python3-usr-local-bin-ansible-playbook-but-this-results-in-you-are-running-python-2-x/25713 "2017-10-10T15:27:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Zucker](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@John\_Zucker](https://forum.ansible.com/u/John_Zucker)\
**Post date:** [October 10, 2017, 3:27pm UTC](https://forum.ansible.com/t/trying-ansible-2-4-py3-as-tech-preview-caling-python3-usr-local-bin-ansible-playbook-but-this-results-in-you-are-running-python-2-x/25713/1 "2017-10-10T15:27:31Z")

</div>

Hi -

I am trying to work out on an experimental basis how to take forward some existing py3 code and line up with my usual practice of running ansible-playbook under python3 to invoke some stuff including aws modules, esp cloudformation.py.

Would much appreciate feedback on the way to go, even if I need to modify some modules, to be roughly in line with the team’s thinking.

Currently, I am baffled.

1. Installation is

$ pip show ansible

Name: ansible

Version: 2.4.0.0

…

Location: /usr/local/lib/python3.6/site-packages

1. Pythons are

/usr/bin/python --version

Python 2.7.10

/usr/local/bin/python --version

Python 3.6.2

with python3 pointing to the latter.

python3 --version

Python 3.6.2

1. I set

$ echo $PYTHONPATH

/usr/local/lib/python3.6/site-packages/

because they are definitely the right ones.

1. So I carefully invoke ansible-playbook from python3. To my surprise it starts off under py3 but manages to invoke p2.

$ python3 /usr/local/bin/ansible-playbook -i inventory/test/hosts.ini create.yml -vvv

ansible-playbook 2.4.0.0

config file = /Users/devopszucker/REPO-AnsibleJiraCfn/mel-vpc-infrastructure/ansible/ansible.cfg

configured module search path = [‘/Users/devopszucker/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]

ansible python module location = /usr/local/lib/python3.6/site-packages/ansible

executable location = /usr/local/bin/ansible-playbook

python version = 3.6.2 (default, Jul 17 2017, 16:44:45) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]

Using /Users/devopszucker/REPO-AnsibleJiraCfn/mel-vpc-infrastructure/ansible/ansible.cfg as config file

Parsed /Users/devopszucker/REPO-AnsibleJiraCfn/mel-vpc-infrastructure/ansible/inventory/test/hosts.ini inventory source with ini plugin

[DEPRECATION WARNING]: The use of ‘include’ for tasks has been deprecated. Use ‘import\_tasks’ for static inclusions or ‘include\_tasks’ for dynamic inclusions. This feature will be removed in a future

release. Deprecation warnings can be disabled by setting deprecation\_warnings=False in ansible.cfg.

[DEPRECATION WARNING]: include is kept for backwards compatibility but usage is discouraged. The module documentation details page may explain more about this rationale… This feature will be removed in

a future release. Deprecation warnings can be disabled by setting deprecation\_warnings=False in ansible.cfg.

statically imported: /Users/devopszucker/REPO-AnsibleJiraCfn/mel-vpc-infrastructure/ansible/roles/network/tasks/create.yml

statically imported: /Users/devopszucker/REPO-AnsibleJiraCfn/mel-vpc-infrastructure/ansible/roles/network/tasks/destroy.yml

PLAYBOOK: create.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

1 plays in create.yml

PLAY [create environment VPC stack for csp] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Using module file /usr/local/lib/python3.6/site-packages/ansible/modules/system/setup.py

ESTABLISH LOCAL CONNECTION FOR USER: devopszucker

EXEC /bin/sh -c ‘echo ~ && sleep 0’

EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /Users/devopszucker/.ansible/tmp/ansible-tmp-1507649127.8217468-231361911445889`” && echo ansible-tmp-1507649127.8217468-231361911445889=“`echo /Users/devopszucker/.ansible/tmp/ansible-tmp-1507649127.8217468-231361911445889`” ) && sleep 0’

PUT /var/folders/d8/wqxz1nsj6337y5bwfrtppmxm0000gn/T/tmpt5ae9u54 TO /Users/devopszucker/.ansible/tmp/ansible-tmp-1507649127.8217468-231361911445889/setup.py

EXEC /bin/sh -c ‘chmod u+x /Users/devopszucker/.ansible/tmp/ansible-tmp-1507649127.8217468-231361911445889/ /Users/devopszucker/.ansible/tmp/ansible-tmp-1507649127.8217468-231361911445889/setup.py && sleep 0’

EXEC /bin/sh -c ‘/usr/bin/python /Users/devopszucker/.ansible/tmp/ansible-tmp-1507649127.8217468-231361911445889/setup.py; rm -rf “/Users/devopszucker/.ansible/tmp/ansible-tmp-1507649127.8217468-231361911445889/” \> /dev/null 2\>&1 && sleep 0’

fatal: [localhost]: FAILED! =\> {

“changed”: false,

“failed”: true,

“module\_stderr”: “Your PYTHONPATH points to a site-packages dir for Python 3.x but you are running Python 2.x!\n PYTHONPATH is currently: "/usr/local/lib/python3.6/site-packages/"\n You should `unset PYTHONPATH` to fix this.\n”,

“module\_stdout”: “”,

“msg”: “MODULE FAILURE”,

“rc”: 0

}

to retry, use: --limit @/Users/devopszucker/REPO-AnsibleJiraCfn/mel-vpc-infrastructure/ansible/create.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

1. As an experiment I have ensured that all system, network and cloud modules in site-packages specify python3.

It makes no difference.

Where does the /bin/sh of /usr/bin/python come from?

What workaround are you recommending?

Thanks a bundle for any hints,

[zuckerjohn@gmail.com](mailto:zuckerjohn@gmail.com)

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 10, 2017, 3:31pm UTC](https://forum.ansible.com/t/trying-ansible-2-4-py3-as-tech-preview-caling-python3-usr-local-bin-ansible-playbook-but-this-results-in-you-are-running-python-2-x/25713/2 "2017-10-10T15:31:20Z")

</div>

Ansible defaults to executing all modules via /usr/bin/python. This is controlled by the ansible\_python\_interpreter variable.

You can read more about that variable at:

[http://docs.ansible.com/ansible/latest/python\_3\_support.html#testing-python-3-module-support](http://docs.ansible.com/ansible/latest/python_3_support.html#testing-python-3-module-support)

[http://docs.ansible.com/ansible/latest/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine](http://docs.ansible.com/ansible/latest/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine)

---

<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:** [October 10, 2017, 3:45pm UTC](https://forum.ansible.com/t/trying-ansible-2-4-py3-as-tech-preview-caling-python3-usr-local-bin-ansible-playbook-but-this-results-in-you-are-running-python-2-x/25713/3 "2017-10-10T15:45:55Z")

</div>

Have you put 'localhost' in inventory? the 'implicit localhost' should  
default to using ansible\_python\_interpreter=sys.executable ... which  
should be python3 in your case.  
If you add it to inventory, 'implicit magic' does not happen and you  
are responsible for setting it.
