node1:192.168.91.139:zabbix-server
node2:192.168.91.137:ansible
在node2:
实现各主机间ssh无密钥通信
[root@localhost ~]#ssh-key
[root@localhost ~]#ssh-copy-id root@192.168.91.137
[root@localhost ~]#ls .ssh/
authorized_keys id_rsa id_rsa.pub known_hosts
[root@localhost ~]#scp -r .ssh/* 192.168.91.139:~/.ssh/
安装ansible
[root@localhost ~]#yum install -y ansible
创建主机清单
[root@localhost ~]#vim /etc/ansible/hosts
[zabbixsrv]
192.168.91.139
测试
[root@localhost ~]#ansible zabbixsrv -m ping
192.168.91.139 | 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/
├── ansible.cfg
├── hosts
└── roles
└── zabbixsrv
├── defaults
├── files
├── handlers
├── meta