是否可以在库存文件中添加ansible_ssh_common_args

时间:2016-07-29 06:20:03

标签: ansible ansible-playbook ansible-2.x

我想使用ansible_ssh_common_args的ProxyCommand跳转/ SSH Bastion Host。 ansible server: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 root@10.10.149.70"'

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  

1 个答案:

答案 0 :(得分:9)

问题在于:

  

ansible_ssh_common_args:&#39; -o ProxyCommand =&#34; ssh -W%h:%p -q root@10.10.149.70"&#39;

替换&#34;:&#34; by&#34; =&#34;并写成这样:

  

ansible_ssh_common_args =&#39; -o ProxyCommand =&#34; ssh -W%h:%p -q root@10.10.149.70"&#39;

为了帮助他人,请注意您的广告资源文件是&#39; .ini&#39;文件。 &#39;的.ini&#39;文件,例如ansible.cfg,使用&#39; =&#39;分配变量,作为&#39; yaml&#39;文件使用&#39;:&#39;