Ansible如何通过跳板机连接目标机器
Ansible如何通过跳板机连接目标机器
修改本地机器ssh的配置文件~/.ssh/config
没有就手动创建一个
本地IP: 192.255.235.20
# 方法一
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测试
ssh prod1
ssh prod2# 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"'Last updated