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'

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

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/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine

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.