我想使用ansible_ssh_common_args的ProxyCommand跳转/ SSH Bastion Host。 ansible服务器:10.10.149.2网关/堡垒主机:10.10.149.70主机连接:10.32.32.190所以我的目标是从10.10.149.2到10.10.149.70(ssh隧道)连接10.32.32.190
ansible --version ansible 2.1.0.0
我的库存:
[local]
10.10.149.2
[Private]
10.32.32.190
[Private:vars]
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q [email protected]"'
pingtest.yml:
---
- hosts: Private
tasks:
- name: test connection
ping:
register: ping1
- debug: var=ping1
问题面临:
fatal: [10.32.32.190]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
所以我怀疑库存文件中的ansible_ssh_common_args支持。我不想使用ssh.config文件。
日志:
[root@mavosdsc ansible]# ansible-playbook -i inventory pingtest.yml -e "user=root" --ask-pass -vvvv
Using /etc/ansible/ansible.cfg as config file
SSH password:
Loaded callback default of type stdout, v2.0
PLAYBOOK: pingtest.yml *********************************************************
1 plays in pingtest.yml
PLAY [Private] *****************************************************************
TASK [setup] *******************************************************************
<10.32.32.190> ESTABLISH SSH CONNECTION FOR USER: None
<10.32.32.190> SSH: EXEC sshpass -d12 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 10.32.32.190 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1469788026.71-124524328003439 `" && echo ansible-tmp-1469788026.71-124524328003439="` echo $HOME/.ansible/tmp/ansible-tmp-1469788026.71-124524328003439 `" ) && sleep 0'"'"''
fatal: [10.32.32.190]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
to retry, use: --limit @pingtest.retry
PLAY RECAP *********************************************************************
10.32.32.190 : ok=0 changed=0 unreachable=1 failed=0
问题出在这里:
ansible_ssh_common_args:' - o ProxyCommand =“ssh -W%h:%p -q [email protected]”'
将“:”替换为“=”,并像这样写:
ansible_ssh_common_args =' - o ProxyCommand =“ssh -W%h:%p -q [email protected]”'
要帮助他人,请记住您的库存文件是'.ini'文件。 '.ini'文件,例如ansible.cfg,使用'='分配变量,因为'yaml'文件使用':'