sup*_*azi 5 python amazon-web-services ansible
我有问题使它工作动态库存的 ec2.py 脚本。
在 CentOS 7 上安装 ansible:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum --enablerepo=epel install ansible
Run Code Online (Sandbox Code Playgroud)
配置一个简单的主机文件和 ssl 密钥访问。运行 ansible:
ansible all -m ping
Run Code Online (Sandbox Code Playgroud)
得到预期的输出。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
Run Code Online (Sandbox Code Playgroud)
在 ~/.aws 中配置凭据文件。运行 aws:
aws ec2 describe-instances
Run Code Online (Sandbox Code Playgroud)
得到预期的输出。Aws-cli 正在运行。
安装boto。
yum --enablerepo=epel install python2-boto
Run Code Online (Sandbox Code Playgroud)
从官方文档中的链接下载 ec2.py 和 ec2.ini ( http://docs.ansible.com/ansible/latest/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script )。运行它我收到以下错误:
[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'
Run Code Online (Sandbox Code Playgroud)
尝试从 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_platformsetattr 循环迭代的列表中缺少该属性。添加它,它就会起作用。
这实际上现在已修复(两小时前):
https://github.com/ansible/ansible/commit/223f94ec563eb0f5fb95465bf440ffddd7828f8b
从 git 中提取最新版本,它应该可以工作。