将Ansible与AWS动态库存一起使用(ec2.py)

时间:2017-10-29 15:30:53

标签: python amazon-web-services amazon-ec2 ansible ansible-inventory

尝试使用ec2.py。

使用静态+动态主机文件

我已尝试过以下指南:

重要的是要说下面的运行工作正在发挥作用!

ansible -m ping tag_Ansible_Test

意思是aws-cli,boto和ec2.py正确安装并正常工作。

现在,在hosts文件中定义以下组(如文档所述)时:

[tag_Ansible_Test]

[backend-test-group:children]
tag_Ansible_Test
ansible -m ping backend-test-group -vvvv

尝试使用该组运行ansible命令时,出现以下错误:

ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /etc/ansible/ec2.py inventory source with script plugin
 [WARNING]: Could not match supplied host pattern, ignoring: backend-test-group

 [WARNING]: No hosts matched, nothing to do

Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

通过设置文件夹结构解决问题如下:

/etc/ansible/combined
- hosts (the original file static+dynamic hosts file)
- ec2.py
- ec2.ini

然后,更改ansible.cfg中的inventory设置:

...
inventory       = /etc/ansible/combined
...

感谢@KonstantinSuvorov提供帮助!