简体   繁体   English

Ansible ec2.py 动态清单错误:ImportError: cannot import name 'ec2'

[英]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.

相关问题 将 Ansible 与 AWS 动态清单 (ec2.py) 结合使用 - Using Ansible with AWS dynamic inventory (ec2.py) Ansible ec2.py无法正常工作 - Ansible ec2.py not working Ansible ec2.py 不返回 AWS 账户中的所有 ec2 实例,它只返回在公共子网中创建的实例 - Ansible ec2.py doesnt return all ec2 instances in the AWS account, it returns only the instances created in public subnets 基于其值的标记名为Ansible的EC2实例的动态脚本清单 - Dynamic script inventory of the EC2 instances with Tag name Ansible basing on its values AWS linux: ansible 2.9.7 使用 ec2.py 和 python 3.7 得到:ImportError: No module named boto, boto do installed - AWS linux : ansible 2.9.7 using ec2.py and python 3.7 getting : ImportError: No module named boto , boto do installed Ansible ec2.py独立运行,但在Playbook中失败 - Ansible ec2.py runs standalone but fails in playbook 导入错误:无法从 AWS EC2 上的“psutil”导入名称“_psutil_linux” - ImportError: cannot import name '_psutil_linux' from 'psutil' on AWS EC2 EC2外部清单脚本因ImportError而失败:没有名为ansible.module_utils的模块 - EC2 external inventory script fails because of ImportError: No module named ansible.module_utils EC2动态清单-按VPC ID过滤实例 - EC2 Dynamic Inventory - Filtering Instances by VPC ID 如何使用Fabric访问AWS的动态EC2库存? - How to access AWS's dynamic EC2 inventory using Fabric?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM