Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to add ansible_ssh_common_args in inventory file

i want to jump/SSH Bastion Host using ProxyCommand of ansible_ssh_common_args. ansible server:10.10.149.2 gateway/Bastion host:10.10.149.70 host to connect:10.32.32.190 So my aim is to connect 10.32.32.190 from 10.10.149.2 trough 10.10.149.70 (ssh tunneling)

ansible --version ansible 2.1.0.0

my inventory:

[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

Issue facing:

 fatal: [10.32.32.190]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}

So i doubt ansible_ssh_common_args support in inventory file.i do not want to use the ssh.config file.

Logs:

   [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  
like image 312
samir Avatar asked Jul 29 '16 06:07

samir


1 Answers

The problem is here:
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q [email protected]"'

Replace ":" by "=" and write like this:
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q [email protected]"'

To help others, keep in mind that your inventory file is a '.ini' file.
'.ini' files e.g ansible.cfg, use '=' to assign variables, as 'yaml' files use ':'.

like image 77
auciomar Avatar answered Oct 30 '22 16:10

auciomar