两台虚拟机ansible:192.168.37.128
zabbix:192.168.37.133
配置ansible
使用yum安装ansible:
yum install epel-release -y
yum install ansible -y
实现主机间密钥通信:
无密钥需要使用ssh-keygen生成密钥
[root@localhost ~]#ssh-keygen(这步ansible和zabbix都需要)
[root@localhost ~]#ls .ssh/ authorized_keys id_rsa id_rsa.pub known_hosts
[root@localhost ~]#scp -r .ssh/* 192.168.91.139:~/.ssh/
创建主机清单:
[root@localhost ~]#vim /etc/ansible/hosts [zabbixsrv] 192.168.37.128
测试:
[root@localhost ~]#ansible zabbixsrv -m ping
192.168.37.133 | SUCCESS => {
"changed": false,
"ping": "pong"
}
(正常)
生成roles文件:
[root@localhost ~]#mkdir /etc/ansible/roles/zabbixsrv/{files,templates,tasks,handlers,vars,defaults,meta} -pv
(查看文件结构)[root@localhost ~]#tree /etc/ansible/
/etc/ansible/