inventory文件配置
inventory是Ansible管理主机信息的配置文件,相当于系统HOSTS文件的功能,默认存放在/etc/ansible/hosts
- 定义主机和组
- inventory可以直接为IP
x.x.x.x- d端口号不是默认的22端口时,可以明确表示
serverX:prot
serverX ansible_port=prot ansible_host=x.x.x.x- 中括号可以表示一个组,也可以表示一个范围
[server]
www[1…x].example.com
db-[a:f].example.com- 定义主机变量
在playbook中使用时对主机进行个性化定制
[web]
web1 http_port=port maxRequestPerChild=1024- [web:vars]
ntp_server = time1.aliyun.com
web组中的所有主机ntp_server的值为time1.aliyun.com- 定义组嵌套及组变量
[apache]
serverX
[nginx]
serverXX
serverXXX
[web:child]
apache
nginx
[web:vars]
time1.aliyun.com
- 组与组之间可以互