ansible 10.0.0.43
客户端 10.0.0.44
1)安装ansible配置1台远程主机
[root@c7-43 ~]# yum -y install ansible
2.设置ssh加速
[root@c7-44 ~]# cat /etc/ssh/sshd_config | grep 'UseDNS'
UseDNS no
GSSAPIAuthentication no
Port 222
[root@c7-44 ~]# systemctl restart sshd #重启sshd
3.设置免密码登录
[root@c7-43 ~]# ssh-keygen
[root@c7-43 ~]# ssh-copy-id [email protected] -p 222 #拷贝公钥时加上端口
4.更改ssh默认连接端口为222
[root@c7-43 ~]# cat /etc/ansible/ansible.cfg | grep 'remote_port'
remote_port = 222
5.ansible添加主机组并测试
[root@c7-43 ~]# cat /etc/ansible/hosts
[lnmp]
10.0.0.44
[root@c7-43 ~]# ansible lnmp -m ping
10.0.0.44 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}