大网数据广告活动
服务器运维问答

Ansible: Dynamic AWS inventory with groups

· 52CE 我爱测

I have setup a mixed (static and dynamic aws) inventory inside my ansible folder. $ ls inventory/ ec2.ini ec2.py inventory.yml The configuration for that is as follows: $ grep 'inventory' ansible.cfg hostfile = ./inventory invent…

问题原文

原帖链接 · cytopia · CC BY-SA 3.0

I have setup a mixed (static and dynamic aws) inventory inside my ansible folder.

$ ls inventory/
ec2.ini
ec2.py
inventory.yml

The configuration for that is as follows:

$ grep 'inventory' ansible.cfg
hostfile = ./inventory
inventory_ignore_extensions = .ini, .pyc, .pyo, .retry

My static inventory has hosts grouped via the ini-style directives. e.g.:

[webservers]
host1.domain.tld
host2.domain.tld
host3.domain.tld

[database]
host4.domain.tld
host5.domain.tld
host6.domain.tld

How can I group hosts in my dynamic inventory?

已采纳解答

原帖链接 · Henrik Pingel · CC BY-SA 4.0

When using an dynamic inventory with Ansible hosts can be grouped and addressed by using tags like this:

---
- hosts: tag_Ansible_Slave
  user: ec2-user
  become: True
  tasks:
   - name: Update all packages to latest
     yum: name=* state=latest

patterns can be used to define hosts based on the combination, intersection, etc of ec2 tags, like this: tag_webservers:&tag_Ansible_Slave

Tags can be set with Ansible with the ec2 module with the instance_tags parameter when initializing the instances in AWS.

You might want to checkout this blog post for further instructions.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。