1. 配置yum源,安装ansible
用阿里云镜像站
]# [root@node5 yum.repos.d]# ls
CentOS-Base.repo
]# yum -y install --downloadonly --downloaddir=/root/ansible ansible //下载便于离线安装
]# yum -y install ansible
]# /etc/ansible/ansible.cfg
...
[defaults]
inventory = /etc/ansible/hosts
host_key_checking = False //ssh连接不用输入yes
]# /etc/ansible/hosts
...
[zabbix_agent]
node3
node5
...
]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.72.12 node3
192.168.72.20 node5
]# ssh-keygen -t rsa -b 2048 -N '' -f key //创建公钥私钥,名为key 公钥key.pub
]# ssh-copy-id -i key.pub node3
]# ssh-copy-id -i key.pub node5
]# ansible zabbix_agent -m ping //测试
node3 | SUCCESS => {
"changed": false,
"ping": "pong"