我想更改 ansible 以在控制器上使用 python3.5。我已经安装了 ansible 和 python3.5,有没有办法将其更改为使用 python3?
ansible 文档建议使用 python3 /usr/bin/ansible localhost -m ping
对 python3 进行测试。但如果这不起作用,请不要提供更多细节。
我的结果是:
Traceback (most recent call last):
File "/usr/bin/ansible", line 32, in <module>
from ansible import context
ImportError: No module named 'ansible'
我也试过 pip3 install ansible 没有运气:
File "<string>", line 1, in <module>
File "/tmp/pip-build-eadti4n6/ansible/setup.py", line 12
print "Ansible now needs setuptools in order to build. " \
^
SyntaxError: Missing parentheses in call to 'print'
原文由 lajmode 发布,翻译遵循 CC BY-SA 4.0 许可协议
按照 Ansible Python 3 支持 页面上的说明,我使用
pip3
在删除之前的 (2.7) 版本后安装了 Ansible:当我收到
ImportError: No module named 'ansible'
错误时,我验证了 Ansible 是可访问的,并发现ansible-playbook
只是一个 Python 脚本:我想可能是安装出了问题,所以我重做了:
原来的卸载只询问删除两个东西,这次提出了一个洗衣清单。重新安装没有下载任何东西,显然是从缓存中收集了所有内容。
我尝试重新运行我的剧本并再次收到
ImportError: No module named 'ansible'
错误。这导致了一个有趣的发现:然后我运行
less /usr/bin/ansible
并在脚本中发现了 shebang 调用#!/usr/bin/python
我怀疑这是一个错误。我编辑了文件,并更改了 shebang 以调用 python3 解释器。结果很能说明问题:显然
pip3
安装未能为ansible
可执行文件设置正确的 shebang。 Searching all of/usr/bin/ansible*
I discoveredansible-connection
also had apython
shebang, rather than apython3
one, but all of the other files were正确的。修复不正确的 shebang 后,我的 playbook 运行正确。