hosts文件(hosts文件修改后无法保存)

简介: 1、正常写法,name1为别名:

[test1]

name1 ansible_ssh_host=192.168.1.111 ansible_ssh_user="root" ansible_ssh_pass="123456" ansible_ssh_port=22

1、正常写法,name1为别名:

[test1]

name1 ansible_ssh_host=192.168.1.111 ansible_ssh_user="root" ansible_ssh_pass="123456" ansible_ssh_port=22

name2 ansible_ssh_host=192.168.1.222 ansible_ssh_user="root" ansible_ssh_pass="123456" ansible_ssh_port=22

2、连续的IP写法,表示192.168.1.20到192.168.1.50,共31台主机:

[test1]

name1 ansible_ssh_host=192.168.1.[20:50] ansible_ssh_user="root" ansible_ssh_pass="123456" ansible_ssh_port=22

3、带参数的群组,vars底下为群组共同便变量,包括已定义变量和自定义变量:

[test1]

name1 ansible_ssh_host=192.168.1.[20:50]

[test1:vars]

ansible_ssh_user=root

ansible_ssh_pass="123456"

testvar="test"

4、群组整合,children底下为父群组test的子群组,调用方式为ansible test -m ping:

[dbtest]

name1 ansible_ssh_host=192.168.1.[20:50] ansible_ssh_user="root" ansible_ssh_pass="123456" ansible_ssh_port=22

[webtest]

name2 ansible_ssh_host=192.168.2.[20:50] ansible_ssh_user="root" ansible_ssh_pass="123456" ansible_ssh_port=22

[test:children]

dbtest

webtest

5、调用两个主机组的写法,以下webservers和dbservers都会被调用:

ansible webservers:dbservers -m win_ping

6、在webservers组中但不在dbsersers中的调用:

ansible webservers:!dbservers -m win_ping

7、在webservers组中并且在dbservers组中的才会调用:

ansible webservers:&dbservers -m win_ping

8、在调用前加~,代表正则表达式:

ansible ~(web|db).*.91it.org -m win_ping

9、组合的例子:

webserver:dbservers:&nginx:!ntp

10、hosts文件中没有定义的IP或别名,在进行调用中,会提示错误。ansible对单台服务器的调用,服务器IP或域名必须有写在hosts里。

关注点赞不迷路[害羞]

本文链接:https://www.zhantian9.com/232712.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2000000@qq.com 举报,一经查实,本站将立刻删除。

发表回复

您的电子邮箱地址不会被公开。