ansible之hosts文件配置

test1代表组名,当然没有组名也可以.

[test1]
name1 ansible_ssh_host=192.168.1.111 ansible_ssh_user=
"root" ansible_ssh_pass="1234" ansible_ssh_port=22
name2 ansible_ssh_host=192.168.1.222  ansible_ssh_user=
"root" ansible_ssh_pass="1234" ansible_ssh_port=22

vars代表变量,并且可以自定义变量如testvar就是自定义

[test1]
name1 ansible_ssh_host=192.168.1.[20:50]
[test1:vars]
ansible_ssh_user=root
ansible_ssh_pass="1234"
testvar="test"

组的整合

[dbtest]
name1 ansible_ssh_host=192.168.1.[20:50] ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22
[webtest]
name2 ansible_ssh_host=192.168.2.[20:50] ansible_ssh_user="root" ansible_ssh_pass="1234" ansible_ssh_port=22
[test:children]
dbtest
webtest
如果需要对dbtest和webtest共同操作,可以直接调用test

其他复杂的组合

ansible webservers:dbservers -m win_ping 调用两组
ansible webservers:!dbservers -m win_ping 在webservers里不在dbservers里的调用
ansible webservers:&dbservers -m win_ping 在这两组里的才调用
ansible ~(web|db).*.91it.org -m win_ping ~代表支持正则表达式
webserver:dbservers:&nginx:!ntp  复杂组合的例子 利用:分开
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容