1.环境准备–关闭防火墙及selinux
三台centos7设备
一台控制节点
两台被控
需要机器之间能够互相解析
vi /etc/hosts
配置ssh公钥认证
控制节点生成key
ssh-keygen
ssh-copy-id -i 192.168.xx #所有的机器
2.控制节点
配置epel源
yum -y install epel-releae
安装ansible
yum install -y ansible
3.主机清单
查看配置文件位置
rpm -qc ansible
/etc/ansible/ansible.cfg #主配置文件
/etc/ansible/hosts #主机清单文件默认位置
vi /etc/ansible/hosts
在最后面添加:
[webservers] #添加主机组
ansible-web2
ansible-web3 #ip 解析都可
[webservers1] #组可以包含其他组
ansible-web2
[webservers2] #组2
ansible-web3
[weball:children] weball包括两个子组
webservers1
webservers2
[weball:vars] #设置变量
ansible_ssh_port=22 #端口号
ansible_ssh_user=root #用户
ansible_ssh_private_key_file=/root/.ssh/id_rsa #可以自定义密码
设置好以后 可以查看一下
[root@zmm1 ~]# ansible weball --list-hosts
hosts (2):
ansible-web2
ansible-web3
测试一下通不通
[root@zmm1