【问题标题】:Ansible ec2.py not workingAnsible ec2.py 不工作
【发布时间】:2018-01-17 09:35:06
【问题描述】:

我无法让它在动态清单的 ec2.py 脚本中运行。

在 CentOS 7 上安装了 ansible:

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum --enablerepo=epel install ansible

配置一个简单的主机文件和 ssl 密钥访问。运行ansible:

ansible all -m ping

获得预期的输出。 Ansible 正在运行。

已安装 aws-cli:

wget -q https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
unzip awscli-bundle.zip
./awscli-bundle/install -i /opt/aws -b /usr/bin/aws

在 ~/.aws 中配置凭证文件。运行 aws:

aws ec2 describe-instances

获得预期的输出。 Aws-cli 正在运行。

安装了boto。

yum --enablerepo=epel install python2-boto

从官方文档 (http://docs.ansible.com/ansible/latest/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script) 中的链接下载 ec2.py 和 ec2.ini。运行它我得到以下错误:

[root@vm09 ansible]# ./ec2.py --list
Traceback (most recent call last):
  File "./ec2.py", line 1642, in <module>
    Ec2Inventory()
  File "./ec2.py", line 193, in __init__
    self.do_api_calls_update_cache()
  File "./ec2.py", line 525, in do_api_calls_update_cache
    self.get_instances_by_region(region)
  File "./ec2.py", line 615, in get_instances_by_region
    self.add_instance(instance, region)
  File "./ec2.py", line 934, in add_instance
    if self.group_by_platform:
AttributeError: 'Ec2Inventory' object has no attribute 'group_by_platform'

尝试从 git 和 pip 安装 ansible,与 boto 相同。总是得到同样的错误。

我在这里缺少什么?

【问题讨论】:

  • 您尝试devel 版本的ec2.py 脚本吗?我最好试试github.com/ansible/ansible/blob/v2.3.1.0-1/contrib/inventory/…
  • 我有完全相同的问题,并且正在使用开发版本。刚刚开始调试,所以还没有答案,但只是说明我看到的和你完全一样(仅在 Ubuntu 上,使用 Python 3.5,来自 pip 的 Ansible)

标签: python amazon-web-services ansible


【解决方案1】:

好的,如果您查看介绍 group_by_platform 功能的 PR:

https://github.com/ansible/ansible/pull/27848/files

您可以看到代码遍历了用于分组选项的可能属性。这些属性在脚本的较高位置可用:

https://github.com/ansible/ansible/blob/devel/contrib/inventory/ec2.py#L435-L462

group_by_platform 属性从 setattr 循环迭代的列表中丢失。添加它,它就会工作。

这实际上已经修复(两小时前):

https://github.com/ansible/ansible/commit/223f94ec563eb0f5fb95465bf440ffddd7828f8b

从 git 中提取最新的,它应该可以工作。

【讨论】:

  • 更新后的 ec2.py 在我的安装中运行。并且也在 Ubuntu 上工作。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 1970-01-01
相关资源
最近更新 更多