程序员

ansible的主机清单配置

2020-05-24  本文已影响0人  南南宫问天

1.分组配置

[web]
172.16.210.53
172.16.210.54
172.16.210.55
[data]
172.16.210.10
[root@ansible ~]# ansible web -a "hostname"
172.16.210.54 | CHANGED | rc=0 >>
web02
172.16.210.55 | CHANGED | rc=0 >>
web03
172.16.210.53 | CHANGED | rc=0 >>
web01

2.主机名符号匹配配置

[web]
172.16.210.[53:55]
172.16.210.[2:254]
[web]
web01
web[01:03] ##前提做好hosts解析

3.支持跟上非标准远程端口

[web]
web01:52113  ##一般用于发生客户端的ssh端口改变

4.主机使用特殊的变量

采用的变量的方式定义用户和密码可以免ssh密钥

172.16.210.[53:55] ansible_ssh_port=52113 ansible_ssh_user=root ansible_ssh_pass=redhat 

报错:

Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host.

解决方法:

解决方法:在ansible.cfg文件中更改下面的参数:
#host_key_checking = False 将#号去掉即可

不用在hosts定义解析使用主机名

web01 ansible_ssh_host=172.16.210.53   

第五种方式: 主机组名嵌入配置

[rsync:children]  ---嵌入子组信息
rsync_server
rsync_client

[rsync_server]
web01 
[rsync_client]
web02  
web03  

嵌入式变量信息:

[web:vars]  ##提前给组定义一些变量
ansible_ssh_host=172.16.210.53
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=redhat
[web]
web01
上一篇 下一篇

猜你喜欢

热点阅读