简体   繁体   中英

Version of Python when running Ansible commands

I am using OSX.10.12.6 .

I installed ansible via pip3 (in order to use it with Python3 considering Python2 is already installed on my machine by default) and downloaded the ec2.py external inventory script from Ansible github

But when running ansible commands, I get the error:

[WARNING]:  * Failed to parse 
~/ec2.py with script plugin: Inventory script
~/ec2.py) had an execution error: Traceback (most recent call last):   File
"~/ec2.py", line 130, in <module>     import boto ImportError: No module named boto

It seems to be because ansible is using Python2 instead of Python3 (I checked, I cannot import boto or ansible from Python2 but I can from Python3). Also I can run successfully the following python3 ec2.py

What is surprising is that if I run ansible --version , I get the following:

ansible 2.8.3
config file = ~/ansible.cfg
configured module search path = ['/Users/XXXX/.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
python version = 3.6.5 (default, Mar 30 2018, 06:42:10) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

Is there anything I can do to "force" ansible to use Python3 instead of Python2?

PS: Note that I can get through the initial error by pip install boto on Python2, but others error pop up and would rather use Python3

FreeBSD Quarterly (Stable) Ports Branch released today 2019Q3 has Ansible 2.7.10 . HEAD upgraded to Ansible 2.8.3 last Sunday! The conclusion is, FreeBSD decided not to put 2.8.3 into the STABLE branch. Probably one of the reasons is the new feature in Ansible 2.8 Python interpreter discovery . See Using FLAVORS . Hence either you downgrade to Ansible 2.7, or you proceed with fixing the HEAD (in MacOS).

It might be worth to try and set ansible_python_interpreter to Python 2.7.


(Some might argue it's rather a comment. I started there, but it's too long.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM