Ansible配置主机清单

 

1)方式一:

#ip+端口+用户+密码
[root@m01 ~]# vim /etc/ansible/hosts 
[web01]
172.16.1.7 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'
[web03]
172.16.1.7 ansible_ssh_port=22

#测试主机清单
[root@m01 ~]# ansible '*' -m ping

 

2)方式二

[root@m01 ~]# vim /etc/hosts
172.16.1.7 web01
172.16.1.9 web03

[root@m01 ~]# vim /etc/ansible/hosts 
[web01]
web01 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'
[web03]
web03 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'

 

3)方式三

[root@m01 ~]# vim /etc/ansible/hosts 
[web1]
web01 
[web3]
web03
[web1:vars]
ansible_ssh_pass='1'
[web3:vars]
ansible_ssh_pass='1'

 

4)基于秘钥的方式

#生成密钥对
[root@m01 ~]# ssh-keygen

#推送秘钥
[root@m01 ~]# ssh-copy-id 172.16.1.7
[root@m01 ~]# ssh-copy-id 172.16.1.9

#配置
[root@m01 ~]# vim /etc/ansible/hosts 
[web1]
web01
[web3]
web03

 

posted @ 2020-10-07 13:48  六月OvO  阅读(509)  评论(0编辑  收藏  举报