CentOS7 安装Ansible
2019-01-08 本文已影响0人
王勇1024
集群机器IP列表
10.136.158.9
10.136.157.11
10.136.157.12
10.136.157.26
iTerm2打开多窗口操作模式
shift+command+i
1.机器互信
生成ssh.key
ssh-keygen -t dsa -f ~/.ssh/id_dsa -P ""
分发ssh.key
ssh-copy-id -i ~/.ssh/id_dsa.pub root@10.136.158.9
ssh-copy-id -i ~/.ssh/id_dsa.pub root@10.136.157.11
ssh-copy-id -i ~/.ssh/id_dsa.pub root@10.136.157.12
ssh-copy-id -i ~/.ssh/id_dsa.pub root@10.136.157.26
2.安装ansible
yum install -y ansible
配置hosts文件
vi /etc/ansible/hosts
添加ip
[mesos]
10.136.158.9
10.136.157.11
10.136.157.12
10.136.157.26
3.测试
[mesos@bj3-136-157-11-c2-128 ~]$ ansible webservers -m command -a 'uptime'
10.136.157.11 | SUCCESS | rc=0 >>
17:15:44 up 63 days, 23:14, 2 users, load average: 0.00, 0.03, 0.06
10.136.157.26 | SUCCESS | rc=0 >>
17:15:44 up 63 days, 23:14, 2 users, load average: 0.01, 0.02, 0.05
10.136.157.12 | SUCCESS | rc=0 >>
17:15:44 up 63 days, 23:14, 2 users, load average: 0.00, 0.01, 0.05
10.136.158.9 | SUCCESS | rc=0 >>
17:15:44 up 4:54, 3 users, load average: 0.14, 0.27, 0.20
尝试访问所有ip
[mesos@bj3-136-157-11-c2-128 ~]$ ansible all -m ping
10.136.157.12 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.136.157.11 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.136.157.26 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.136.158.9 | SUCCESS => {
"changed": false,
"ping": "pong"
}