在 Ansible 中创建 EC2 动态库存时出错

在 Ansible 中创建 EC2 动态库存时出错

我是 Ansible 新手。我一直在使用以下教程来设置动态清单-https://aws.amazon.com/blogs/apn/getting-started-with-ansible-and-dynamic-amazon-ec2-inventory-management/

运行 ec2.py 时,出现以下错误- 错误:库存脚本(ec2.py)发生执行错误:回溯(最近一次调用):文件“/etc/ansible/ec2.py”,第 130 行,来自 boto 导入 elasticache ImportError:无法导入名称 elasticache

有人能指出哪里出了问题吗?

答案1

看起来你需要安装 boto 模块

pip install boto

应该为你做到这一点。

答案2

在 Ubuntu(至少在 12.04 上),如果你通过 PIP 安装 python 模块,/usr/local/lib/python2.7/dist-packages其他人将无法读取 - 只有 root 用户和员工组可以读取

drwxr-s---  6 root staff  4096 Jan  7 22:04 awscli
drwxr-s---  2 root staff  4096 Jan  7 22:04 awscli-1.9.17.dist-info
drwxr-s---  6 root staff  4096 Dec 28 22:07 beaver
drwxr-s---  2 root staff  4096 Dec 28 22:07 Beaver-31-py2.7.egg-info
drwxr-s--- 57 root staff  4096 Dec 28 22:07 boto
drwxr-s---  2 root staff  4096 Dec 28 22:07 boto-2.38.0.dist-info
drwxr-s---  5 root staff  4096 Jan  7 21:54 botocore
drwxr-s---  2 root staff  4096 Jan  7 21:54 botocore-1.3.17.dist-info

最简单的解决方案是(不对 dist 目录进行权限更改)将您的用户添加到员工组:

usermod -aG staff USERNAME

答案3

如果你从 Ansible ppa 安装 Ansible

https://launchpad.net/~ansible/+archive/ubuntu/ansible

然后你的 Ansible 就会使用 Ubuntu 中的 python 2.7 包进行安装。

您需要安装 python-boto,有两种方法可以做到这一点:

  1. python-boto在你的 Ubuntu 系统中安装该包:

    sudo apt-get install python-boto

  2. boto在系统 python 中使用 pip安装该包,不建议,避免这种情况,因为您将来会在 apt 安装的作为依赖项的 python 包和使用pip

    sudo pip install boto

答案4

大家好,我也遇到了同样的问题。我的设置如下:

  • Mac OSX 10.11.6
  • Python 2.7.13
  • Ansible 2.3.0.0
  • 博托 2.46.1

我正在运行 homebrew,并且尝试重新安装 ansible 和 boto,但没有成功。我一直收到错误消息:

ERROR! Attempted to execute "inventories/ec2.py" as inventory script: Inventory script (inventories/ec2.py) had an execution error: Traceback (most recent call last): File "/Users/myname/Sites/admin/ansible/inventories/ec2.py", line 130, in <module> from boto import elasticache ImportError: cannot import name elasticache

寻求任何帮助。谢谢!

相关内容