简体   繁体   English

运行Ansible命令时的Python版本

[英]Version of Python when running Ansible commands

I am using OSX.10.12.6 . 我正在使用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 我通过pip3安装了ansible(为了将其与Python3一起使用,因为默认情况下我的计算机上已经安装了Python2),并从Ansible github下载了ec2.py外部清单脚本

But when running ansible commands, I get the error: 但是在运行ansible命令时,出现错误:

[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). 似乎是因为ansible使用的是Python2而不是Python3(我检查过,我无法从Python2导入boto或ansible,但可以从Python3导入)。 Also I can run successfully the following python3 ec2.py 我也可以成功运行以下python3 ec2.py

What is surprising is that if I run ansible --version , I get the following: 令人惊讶的是,如果我运行ansible --version ,则会得到以下信息:

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? 我能做些什么来“强迫”使用Python3而不是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 PS:请注意,我可以通过在Python2上进行pip install boto来解决最初的错误,但是会弹出其他错误,而宁愿使用Python3

FreeBSD Quarterly (Stable) Ports Branch released today 2019Q3 has Ansible 2.7.10 . FreeBSD Quarterly(Stable)Ports Branch今天发布了2019Q3的 Ansible 2.7.10 HEAD upgraded to Ansible 2.8.3 last Sunday! HEAD在上周日升级到Ansible 2.8.3 The conclusion is, FreeBSD decided not to put 2.8.3 into the STABLE branch. 结论是,FreeBSD决定不将2.8.3放入STABLE分支。 Probably one of the reasons is the new feature in Ansible 2.8 Python interpreter discovery . 可能的原因之一是Ansible 2.8 Python解释器发现中的新功能。 See Using FLAVORS . 请参阅使用FLAVORS Hence either you downgrade to Ansible 2.7, or you proceed with fixing the HEAD (in MacOS). 因此,您可以降级到Ansible 2.7,或者继续修复HEAD(在MacOS中)。

It might be worth to try and set ansible_python_interpreter to Python 2.7. 可能值得尝试将ansible_python_interpreter设置为Python 2.7。


(Some might argue it's rather a comment. I started there, but it's too long.) (有些人可能会认为这是一个评论。我从这里开始,但时间太长了。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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