1.准备镜像:
1007 docker run -itd --name client2 ff37bc5ab732
1008 docker run -itd --name client ff37bc5ab732
1009 docker run -itd --name client1 ff37bc5ab732
1010 docker run -itd --name ansible ff37bc5ab732
1011 docker exec -it ansible /bin/bash
2.容器ansible安装:
yum --enablerepo=epel -y install ansible openssh-clients
## db-[99:101]-node.example.com
# write clients you manage
172.17.0.2
# possible to group
# define any group name you like
[target_servers]
# write clients to be grouped
172.17.0.2
172.17.0.3
172.17.0.4
172.17.0.5
3.客户端安装SSH-Agent.:简单两步完成:
ansible:
ssh-keygen -t rsa
ssh 172.17.0.5 mkdir -p .ssh
cat .ssh/id_rsa.pub | ssh 172.17.0.5 ‘cat >> .ssh/authorized_keys‘
ssh 172.17.0.5测试一下,秒过:
4.ansible安装成功:
[root@784390b5dd19 /]# ansible target_servers -m ping
172.17.0.5 | SUCCESS => {
"changed": false,
"ping": "pong"
}
172.17.0.4 | SUCCESS => {
"changed": false,
"ping": "pong"
}
172.17.0.3 | SUCCESS => {
"changed": false,
"ping": "pong"
}
172.17.0.2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@784390b5dd19 /]#
[root@784390b5dd19 /]# ansible target_servers -k -m command -a "uptime"
SSH password:
172.17.0.5 | SUCCESS | rc=0 >>
07:07:33 up 22:13, 1 user, load average: 0.40, 0.12, 0.07
172.17.0.2 | SUCCESS | rc=0 >>
07:07:34 up 22:13, 1 user, load average: 0.40, 0.12, 0.07
172.17.0.3 | SUCCESS | rc=0 >>
07:07:34 up 22:13, 1 user, load average: 0.40, 0.12, 0.07
172.17.0.4 | SUCCESS | rc=0 >>
07:07:34 up 22:13, 1 user, load average: 0.40, 0.12, 0.07
[root@784390b5dd19 /]#
原文:http://www.cnblogs.com/Jt00/p/6971331.html