1)设置主机名和hosts文件
2)配置阿里云repo源
Wget -O /etc/yum.repos.d/aliyun.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3)创建ssh免交互登录
[root@ansible ~]# ssh-keygen -t rsa -P "" -f .ssh/id_rsa
[root@ansible ~]# sshpass -p 666666 ssh root@192.168.30.24 -o StrictHostKeyChecking=no
[root@ansible ~]# sshpass -p 666666 ssh-copy-id root@192.168.30.24 -o StrictHostKeyChecking=no
测试
[root@ansible ~]# ssh root@192.168.30.25
Last login: Wed May 15 17:07:10 2019 from ansible
[root@client1 ~]# hostname
client1
[root@client1 ~]# exit
登出
4)在/etc/ansible/hosts文件中添加管理主机组,以后可根据组成员进行批量管理
vim /etc/ansible/hosts
[cloud]
192.168.30.25
192.168.30.26
[root@ansible ~]# ansible cloud -m ping
client1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@ansible ~]# ansible cloud -a "free -m"
client1 | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 1982 959 84 15 939 696
Swap: 2047 365 1682