[
10.1.0.17 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh.”,
“unreachable”: true
}
]
So I tried command : [ ansible -m ping web-servers:2222 ]
But i am still getting the error as : [ [WARNING]: provided hosts list is empty, only localhost is available ]
hi ,
can you please let me know the exact procedure,becaue i’m also facing the same Issue.
i have installed ansible on redhat 7.2 and trying to ping another RHEL 7.2 host.
i have generated the ssh keys with empty phrase ssh-keygen -b 4096 -t rsa.
Copied ssh-copy-id -i ~/.ssh/id_rsa 10.43.29.222
post which also i’m getting the error
[root@mohan-ansible-host .ssh]# ansible -vvv 10.43.29.222 -m ping
Using /etc/ansible/ansible.cfg as config file
<10.43.29.222> ESTABLISH SSH CONNECTION FOR USER: None
<10.43.29.222> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%C 10.43.29.222 ‘/bin/sh -c ‘"’"’( umask 22 && mkdir -p “echo $HOME/.ansible/tmp/ansible-tmp-1463566172.52-106734337159380” && echo “echo $HOME/.ansible/tmp/ansible-tmp-1463566172.52-106734337159380” )’"’"’’
10.43.29.222 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh.”,
“unreachable”: true
}
I was facing the same issue and during my troubleshooting today I figured out what was the error…
To see if you are facing the same issue as I did check out what is the user you are using on your host machine and the target machine, it should be same user.
you can create a file called server as the example below:
weslley@weslley:/etc/ansible/group_vars$ pwd
/etc/ansible/group_vars
weslley@weslley:/etc/ansible/group_vars$ ls
servers
with the content :
weslley@weslley:/etc/ansible/group_vars$ cat servers
ansible_ssh_user: YOURUSER
I figured out it when I used the command below:
weslley@weslley:/etc/ansible$ ansible -m ping ubuntu_server -vvvv
Using /etc/ansible/ansible.cfg as config file
Loaded callback minimal of type stdout, v2.0
<192.168.56.101> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.56.101> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/weslley/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.56.101 ‘/bin/sh -c ‘"’"‘mkdir -p “echo $HOME/.ansible/tmp/ansible-tmp-1463661558.68-128007589013983” && echo “echo $HOME/.ansible/tmp/ansible-tmp-1463661558.68-128007589013983”’"’"’’
ubuntu_server | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh.”,
“unreachable”: true
}
weslley@weslley:/etc/ansible$ ls
ansible.cfg group_vars hosts roles
weslley@weslley:/etc/ansible$ cd group_vars/
weslley@weslley:/etc/ansible/group_vars$ ls
servers
weslley@weslley:/etc/ansible/group_vars$ cat servers
ansible_ssh_user: root
weslley@weslley:/etc/ansible/group_vars$ ls
servers
weslley@weslley:/etc/ansible/group_vars$ sudo vim servers
weslley@weslley:/etc/ansible/group_vars$ cat servers
ansible_ssh_user:weslley
weslley@weslley:/etc/ansible/group_vars$ ansible -m ping ubuntu_server -vvvv
Using /etc/ansible/ansible.cfg as config file
ERROR! failed to combine variables, expected dicts but got a ‘dict’ and a ‘AnsibleUnicode’:
{}
“ansible_ssh_user:weslley”
weslley@weslley:/etc/ansible/group_vars$ sudo vim servers
weslley@weslley:/etc/ansible/group_vars$ ansible -m ping ubuntu_server -vvvv
Using /etc/ansible/ansible.cfg as config file
Loaded callback minimal of type stdout, v2.0
<192.168.56.101> ESTABLISH SSH CONNECTION FOR USER: weslley
<192.168.56.101> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=weslley -o ConnectTimeout=10 -o ControlPath=/home/weslley/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.56.101 ‘/bin/sh -c ‘"’"’( umask 22 && mkdir -p “echo $HOME/.ansible/tmp/ansible-tmp-1463661672.9-278056820993214” && echo “echo $HOME/.ansible/tmp/ansible-tmp-1463661672.9-278056820993214” )’"’"’’
@Sampada_Jain
I’m getting below error.
But i’m able to ssh root@54.254.224.30… Not able to using ansible. Please help. I have added host on /etc/ansible/hosts
$ ansible all -a “yum update”
54.254.224.30 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh.”,
“unreachable”: true
}
I did… I have created SSH-key and added to destination server.
I have using Cygwin on windows… I’m able to ssh root@52.221.230.55. But once i tired — ansible all -a “yum update”
Below the error :
52.221.230.55 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh.”,
“unreachable”: true
}