我在MAC High Sierra 10.13.3上安装了ansible,当我试图运行时
" ansible --version"我收到以下错误
-bash:/ usr / local / bin / ansible:/usr/local/opt/python/bin/python2.7:bad interpreter:没有这样的文件或目录
如果您遇到同样的问题或有解决方案,请告诉我。
答案 0 :(得分:1)
在我的情况下,我使用pyenv来管理我的python版本,$ PATH和符号链接都指向正确的路径。
$ pyenv which python
/Users/<username>/.pyenv/versions/3.7.3/bin/python
$ which python
/Users/<username>/.pyenv/shims/python
/usr/local/bin/ansible
的可配置配置指出了正确的python版本3.7
#!/usr/local/opt/python/bin/python3.7
.
.
.
但是ansible --version
返回了python 2.7作为其解释器
$ ansible --version
ansible 2.9.12
configured module search path = ['/Users/<username>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/<username>/.pyenv/versions/2.7.16/lib/python2.7/site-packages/ansible
executable location = /Users/<username>/.pyenv/versions/2.7.16/bin/ansible
python version = 2.7.16 (default, Apr 2 2020, 13:02:51) [Clang 11.0.3 (clang-1103.0.32.29)]
Official ansible docs说要使用pip3来为python3安装ansible,我卸载了ansible并使用pip3重新安装了,但交互者仍然指向python2.7。
最后,我在自己的主路径中手动添加了.ansible.cfg文件,并配置了通过添加手动解释的python
ansible_python_interpreter=/usr/bin/python
Example config file for ansible.cfg
现在ansible已为python3正确配置
ansible 2.9.12
config file = /Users/<username>/.ansible.cfg
configured module search path = ['/Users/<username>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/<username>/.pyenv/versions/3.7.3/lib/python3.7/site-packages/ansible
executable location = /Users/<username>/.pyenv/versions/3.7.3/bin/ansible
python version = 3.7.3 (default, Apr 2 2020, 13:02:51) [Clang 11.0.3 (clang-1103.0.32.29)]
答案 1 :(得分:0)
/ usr / local / bin / ansible在第一行有PATH“/usr/local/opt/python/bin/python2.7”。在/ usr / local / opt / python / bin /目录下我有python3.6而不是python2.7。
所以我在文件“vi / usr / local / bin / ansible”
上更改了PATH来自#!/ usr / local / opt / python / bin / python2.7 到#!/ usr / local / opt / python / bin / python3.6 并修复了问题
验证:
ravipatel-ltm2:~ravi.patel $ ansible --version ansible 2.5.0 配置文件=无 配置模块搜索路径= ['/Users/ravi.patel/.ansible/plugins/modules','/ usr / share / ansible / plugins / modules'] ansible python module location = /Users/ravi.patel/Library/Python/3.6/lib/python/site-packages/ansible 可执行位置= / usr / local / bin / ansible python version = 3.6.4(默认,2018年3月1日,18:36:50)[GCC 4.2.1兼容的Apple LLVM 9.0.0(clang-900.0.39.2)]
ravipatel-ltm2:~ravi.patel $ ansible localhost -m ping
localhost | SUCCESS =&gt; { “改变了”:错误, “乒乓” }
ravipatel-ltm2:~ravi.patel $ ansible localhost -m setup -a'filter = ansible_distribution'
localhost | SUCCESS =&gt; { “ansible_facts”:{ “ansible_distribution”:“MacOSX” }, “改变”:错误 }
答案 2 :(得分:0)
更改python版本可能会导致一些兼容性问题
当操作系统中安装了多个python版本时,就会发生这种情况。
简单的故障排除步骤:
我希望它将解决该错误。