[英]Ansible ec2.py dynamic inventory errors: ImportError: cannot import name 'ec2'
My current machine crashed and I have to setup ansible again on the new one using the same methodologies but It seems I am missing somethings.我当前的机器崩溃了,我必须使用相同的方法在新机器上再次设置 ansible,但似乎我遗漏了一些东西。 I need to use version 2.X for consistency reasons as we have not upgraded yet.
出于一致性原因,我需要使用 2.X 版,因为我们还没有升级。
I heavily used ec2.py and ec2.ini so when I run我大量使用 ec2.py 和 ec2.ini 所以当我运行时
~ python /Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py
Traceback (most recent call last):
File "/Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py", line 172, in <module>
from ansible.module_utils import ec2 as ec2_utils
ImportError: cannot import name 'ec2' from 'ansible.module_utils' (/Users/joseph/.pyenv/versions/pypy3.8-7.3.7/lib/pypy3.8/site- packages/ansible/module_utils/__init__.py)
Here is my setup.Fresh MacBook Pro M1.这是我的 setup.Fresh MacBook Pro M1。
#Mac, no prior ansible installation either brew or pip
#Check Python version
➜ ~ python --version
Python 3.8.12 (9ef55f6fc369, Oct 25 2021, 05:10:01)
[PyPy 7.3.7 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.3)]
#Check version used by shebang
➜ ~ /usr/bin/env python --version
Python 3.8.12 (9ef55f6fc369, Oct 25 2021, 05:10:01)
[PyPy 7.3.7 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.3)]
## Check ansible version. Had to use version 2 for now. Installed with pip over python installed by peen
➜ ~ ansible --version
ansible 2.10.17
config file = /Users/joseph/.ansible.cfg
configured module search path = ['/Users/joseph/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/joseph/.pyenv/versions/pypy3.8-7.3.7/lib/pypy3.8/site-packages/ansible
executable location = /Users/joseph/.pyenv/versions/pypy3.8-7.3.7/bin/ansible
python version = 3.8.12 (9ef55f6fc369, Oct 25 2021, 05:10:01)[PyPy 7.3.7 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.3)]
#Run ec2.py inventory script
➜ ~ python /Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py
Traceback (most recent call last):
File "/Users/joseph/infrastructure_as_code/ansible_projects/inventory/ec2.py ", line 172, in <module>
from ansible.module_utils import ec2 as ec2_utils
ImportError: cannot import name 'ec2' from 'ansible.module_utils' (/Users/joseph/.pyenv/versions/pypy3.8-7.3.7/lib/pypy3.8/site- packages/ansible/module_utils/__init__.py)
#$PATH
/Users/joseph/.sdkman/candidates/java/current/bin:/Users/joseph/.pyenv/plugins/pyenv- virtualenv/shims:/Users/joseph/.pyenv/shims:/Users/joseph/.pyenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
## Content of ~/.ansible.cfg
[defaults]
interpreter_python=/Users/joseph/.pyenv/shims/python
## Which python
/Users/joseph/.pyenv/shims/python
## other python
➜ ~ pyenv versions
system
3.10.2
3.8.12
ansible-2x
* pypy3.8-7.3.7 (set by /Users/joseph/.pyenv/version)
pypy3.8-7.3.7/envs/ansible-2x
I have read couple of solution around about the PATH and had high hopes about the interpreter_python setting in the config file but none of that worked.我已经阅读了一些关于 PATH 的解决方案,并对配置文件中的 interpreter_python 设置寄予厚望,但都没有奏效。 So I am not sure what is wrong were, I have also switched to different version of python but it did nothing.
所以我不确定出了什么问题,我也切换到不同版本的 python 但它什么也没做。 Not sure what's missing, I would appreciate some hand in fixing this.
不确定缺少什么,我将不胜感激帮助解决这个问题。 Thanks in advance
提前致谢
It's because you have ansible v2.10.17 whereas that file only exists in the v2.9 series: https://github.com/ansible/ansible/blob/v2.9.27/lib/ansible/module_utils/ec2.py这是因为您有 ansible v2.10.17 而该文件仅存在于 v2.9 系列中: https://github.com/ansible/ansible/blob/v2.9.27/lib/ansible/module_utils/ec2.py
In the future, pip freeze
will emit a requirements.txt file with the versions pinned to the current ones in use, which can help this kind of drift将来,
pip freeze
将发出一个 requirements.txt 文件,其中的版本固定到当前使用的版本,这可以帮助这种漂移
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.