# 方法一
Host bastion
HostName 192.255.235.63 # 跳板机IP
BatchMode yes
User ubuntu
Host prod1
HostName 172.16.105.45
ServerAliveInterval 60
TCPKeepAlive yes
IdentityFile ~/.ssh/keys/bastion_id_rsa # 跳板机上的 免密 文件
ProxyCommand ssh bastion 'nc -w 14400 %h %p' # or ProxyCommand ssh -W %h:%p bastion
User ubuntu
Port 22
# 方法二
Host prod2
HostName 150.138.xx.xxx
IdentityFile ~/.ssh/id_rsa # 跳板机上的 免密 文件
ProxyCommand ssh -qaY -i ~/.ssh/id_rsa -p 22 跳板机用户@跳板机IP 'nc -w 14400ms %h %p'
Port 10666
User root
# hosts
[prod]
prod2
# 配置完成之后测试 ansible 是否能连接到机器
ansible prod -m ping
[prod]
ansible_ssh_common_args='-o ProxyCommand="/usr/bin/ncat --proxy ip:port --proxy-type http %h %p"'