Error while Install and Configure ‘Ansible’ Automation Tool for IT Management


#1

Hi I am trying to set up a ansible lab on azure cloud and trying to get hand on to replace puppet actually. and referring to link : http://www.tecmint.com/install-and-configure-ansible-automation-tool-in-linux/#comments
But when I m trying to run : [ ansible -m ping web-servers ]
I am getting a error as : as mentioned below in-between [ ]

[
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 ]

Can somebody help me please

Thank you
Sampada


#2

Can you connect to 10.1.0.17 via SSH?

ssh root@10.1.0.17


#3

Yeah I can connect to root through SSH.

root@Ansible1:~# ssh root@10.1.0.17
root@10.1.0.17’s password:
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-58-generic x86_64)

  • System information as of Fri Apr 22 06:50:07 UTC 2016*

  • System load: 0.11 Processes: 113*

  • Usage of /: 3.7% of 28.80GB Users logged in: 1*

  • Memory usage: 10% IP address for eth0: 10.1.0.17*

  • Swap usage: 0%*

Last login: Fri Apr 22 06:50:07 2016 from 10.1.0.16
root@Ansible2:~# logout
Connection to 10.1.0.17 closed.
root@Ansible1:~#


#4

@Sampada_Jain

Could you try to ping to the host with the help of below command.

# ansible all -i 'webserver-IP,' -c local -m ping

#5

Yes it do work.But it only pings the local host I hope.

root@Ansible1:~# ansible all -i ‘webserver-IP,’ -c local -m ping
webserver-IP | SUCCESS => {

  • “changed”: false,*
  • “ping”: “pong”*
    }

#6

@Sampada_Jain

I think you should check your Ansible host configuration file, this file is the responsible for everything…


#7

Thank you everyone.

Its is working. There was some issue while coping the ssh signature to the node. Got it fixed. Thank you all for giving your inputs.


#8

@Sampada_Jain

Can you share with our readers how you fixed?


#9

Private key was not generated. I explicitly generated by the below command and get that copied in the other node machines.

ssh-keygen -b 4096 -t rsa


#10

Thanks for sharing…and good luck for your project that you working on.


#11

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.

  1. i have generated the ssh keys with empty phrase ssh-keygen -b 4096 -t rsa.
  2. 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
    }

#12

Hey @Mohan_Swarna,

Are you able to SSH 10.43.29.222 from your current Host.?
Have you edited Ansible/hosts?


#13

Hello,

I have been facing the same issue and I already have copied in the another node and I can ssh its guest machine.

I believe we can work out to figure out what is our problem @Mohan_Swarna

Here is my hosts @Sampada_Jain:

[servers]
ubuntu_server ansible_ssh_host=192.168.56.101

Is there anything we would be missing?

Regards.


#14

Hello guys,

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” )’"’"’’

^C [ERROR]: User interrupted execution

weslley@weslley:/etc/ansible/group_vars$ ansible -m ping ubuntu_server
ubuntu_server | SUCCESS => {
“changed”: false,
“ping”: “pong”
}

If you have any doubts about my explanation, please let me know.

Best Regards.


#15

@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
}


#16

Hi have you generated sshkey, if not generate ssh key and copy it to remote host.


#17

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
}

Please help.


#18

And also once share the content of your ansible hosts file /etc/ansible/hosts


#19

@raghuu

$ cat /etc/ansible/hosts
52.221.230.55


#20

Do one thing add ssh_key, ssh_user variables to the hosts file and try again

#vim /etc/ansible/hosts

52.221.230.55       ansible_ssh_pass=password ansible_ssh_user=user

and also share the output of below cmd

#ansible -m ping 52.221.230.55 -vvv