1.环境介绍
172.20.16.15 Ansible 服务器
192.168.1.2 跳板机(当代理)192.168.11.51-53 远程机(与ansible网络不通)2.必要条件
1)172.20.16.15与192.168.1.2之间免密钥
2)192.168.1.2与192.168.11.51-53之间网络正常3) 跳板机机器安装nc(只首次执行需要依赖)3.部署过程
创建免密钥(ansible机器操作)
ssh-keygen
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.2
创建ansible配置文件
vim /home/liwenbin/ansible.txt
[proxy]
192.168.1.[2:15] ansible_ssh_user=root idc=bjal ansible_ssh_pass=W7Kh15wjvHpzMqV5
192.168.11.[51:53] ansible_ssh_user=root idc=bjal ansible_ssh_pass=W7Kh15wjvHpzMqV5
创建ssh proxy配置
vim .ssh/config
Host bastion
User root
HostName 192.168.1.2
ProxyCommand none
BatchMode yes
Host 192.168.11.*
ServerAliveInterval 60
TCPKeepAlive yes
ProxyCommand ssh -qaY bastion 'nc -w 14400ms %h %p' #or ProxyCommand ssh -W %h:%p bastion
ControlMaster auto
4.测试
ansible -i /home/liwenbin/ansible.txt 192.168.11.* -m command -a 'ls' #测试是否正常
ansible -i /home/liwenbin/ansible.txt 192.168.11.* -m command -a 'yum install rsync -y‘ #安装依赖
ansible -i /home/liwenbin/ansible.txt 192.168.11.* -m synchronize -a 'src=/etc/yum.repos.d dest=/root/' #测试同步文件
精彩评论