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.
- Installation is
$ pip show ansible
Name: ansible
Version: 2.4.0.0
…
Location: /usr/local/lib/python3.6/site-packages
- 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
- I set
$ echo $PYTHONPATH
/usr/local/lib/python3.6/site-packages/
because they are definitely the right ones.
- 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 ********************************************************************
- 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,