我在让它运行动态 list 的 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 key 访问。运行 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 相同。总是得到同样的错误。
我在这里缺少什么?
最佳答案
好的,如果您查看引入了 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 中拉取最新的,它应该可以工作。
关于python - Ansible ec2.py 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45591627/