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'

29 views
Skip to first unread message

John Zucker

unread,
Oct 10, 2017, 11:27:31 AM10/10/17
to Ansible Project
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


2. 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


3. I set 

$ echo $PYTHONPATH 

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

because they are definitely the right ones.


4. 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

<localhost> ESTABLISH LOCAL CONNECTION FOR USER: devopszucker

<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'

<localhost> 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'

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

<localhost> 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'

<localhost> 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 ********************************************************************


5. 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,

zucke...@gmail.com


Matt Martz

unread,
Oct 10, 2017, 11:32:15 AM10/10/17
to ansible...@googlegroups.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:


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e9982f30-67d7-45f1-bf09-7af5d9bfceb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Brian Coca

unread,
Oct 10, 2017, 11:46:13 AM10/10/17
to Ansible Project
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.





--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages