2017-08-09 75 views
3

我有问题可以使ec2.py脚本适用于动态清单。在CentOS 7Ansible ec2.py不能正常工作

安装ansible:

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

配置一个简单的hosts文件和SSL密钥访问。运行:

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正在工作。

安装博托。

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。运行它我得到以下错误:

[[email protected] 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相同。总是得到相同的错误。

我在这里失踪了什么?

+1

您是否尝试ec2.py脚本的'devel'版本?我最好使用https://github.com/ansible/ansible/blob/v2.3.1.0-1/contrib/inventory/ec2.py –

+0

尝试一下,我有完全相同的问题,并使用devel版本。刚开始调试,所以没有答案,但只是一个说明我看到完全一样的你(只在Ubuntu上,Python 3.5,Ansible从PIP) –

回答

2

好了,如果你看一下所引入的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的最新的,它应该工作。

+0

更新的ec2.py正在我的安装。并且也在研究Ubuntu。谢谢。 – supervazi