首页 文章

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

提问于
浏览
1

尝试使用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 回答

  • 1

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

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

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

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

    感谢@KonstantinSuvorov提供帮助!

相关问题