安装
yum install epel-release -y
yum install ansible –y
ansible 程序结构
安装目录如下(yum安装):
配置文件目录:/etc/ansible/
执行文件目录:/usr/bin/
Lib库依赖目录:/usr/lib/pythonX.X/site-packages/ansible/
Help文档目录:/usr/share/doc/ansible-X.X.X/
Man文档目录:/usr/share/man/man1/
编辑主机配置文件
vim /etc/ansible/hosts
[Client]
192.168.64.135
192.168.64.140
192.168.64.136
192.168.64.137
命令查看主机列表
ansible Client --list
ansible 配置公私钥
ssh-keygen 回车 连续按3下 密钥就形成了
分发密钥(保证可以通信情况下 进行密钥分发)
ssh-copy-id root@192.168.64.135
ssh-copy-id root@192.168.64.1356
ssh-copy-id root@192.168.64.137 等
分发完成
测试一下
ansible Client -m ping
192.168.64.140 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.64.136 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.64.135 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.64.137 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.64.137 port 22: No route to host",
"unreachable": true
}
大功告成了