我已经在我的安全文件夹中设置了一个混合(静态和dynamicaws)库存。
$ ls inventory/ ec2.ini ec2.py inventory.yml
configuration如下:
$ grep 'inventory' ansible.cfg hostfile = ./inventory inventory_ignore_extensions = .ini, .pyc, .pyo, .retry
我的静态库存已经通过ini-style指令分组主机。 例如:
[webservers] host1.domain.tld host2.domain.tld host3.domain.tld [database] host4.domain.tld host5.domain.tld host6.domain.tld
我如何将dynamic库存中的主机分组?
在Ansible中使用dynamic inventory ,可以使用如下tags对主机进行分组和编址:
--- - hosts: tag_Ansible_Slave user: ec2-user become: True tasks: - name: Update all packages to latest yum: name=* state=latest
模式可以用来定义基于ec2标签的组合,相交等主机,如下所示: tag_webservers:&tag_Ansible_Slave
在AWS中初始化实例时,标签可以通过带有带有instance_tags参数的ec2模块的 Ansible进行设置。
你可能想要结账这个博客文章进一步的说明。