具有静态库存的组变量
建议你根据主机(角色)的目的以及地理位置或数据中心位置(如果适用)定义组:
文件 inventory/production
[rogue-server]
192.168.1.1
[atlanta-webservers]
www-atl-1.example.com
www-atl-2.example.com
[boston-webservers]
www-bos-1.example.com
www-bos-2.example.com
[atlanta-dbservers]
db-atl-1.example.com
db-atl-2.example.com
[boston-dbservers]
db-bos-1.example.com
# webservers in all geos
[webservers:children]
atlanta-webservers
boston-webservers
# dbservers in all geos
[dbservers:children]
atlanta-dbservers
boston-dbservers
# everything in the atlanta geo
[atlanta:children]
atlanta-webservers
atlanta-dbservers
# everything in the boston geo
[boston:children]
boston-webservers
boston-dbservers
文件 group_vars/all
文件 group_vars/atlanta-webservers
文件 group_vars/boston-webservers
文件 host_vars/www-bos-2.example.com
运行 ansible-playbook -i inventory/hosts install-apache.yml 之后(剧本中的主持人将是 hosts: all)
端口将是
| 地址 | 端口 | 
|---|---|
| 192.168.1.1 | 80 | 
| www-atl-1.example.com | 1080 | 
| www-atl-2.example.com | 1080 | 
| www-bos-1.example.com | 8080 | 
| www-bos-2.example.com | 8111 |