# Issues with connecting to a host

**URL:** <https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147>\
**Category:** Ansible Project\
**Created:** [December 13, 2013, 12:04am UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147 "2013-12-13T00:04:47Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drew\_Decker](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Drew\_Decker](https://forum.ansible.com/u/Drew_Decker)\
**Post date:** [December 13, 2013, 12:04am UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/1 "2013-12-13T00:04:47Z")

</div>

I’m having a weird issue with only one of my hosts that I’m trying to connect with. I initially had this issue with Ansible 1.3, but I decided to test it using the dev trunk (ansible 1.5 (devel dc41912158) last updated 2013/12/12 17:55:33 (GMT -500)) and it still doesn’t work, so I figured I’d reach out to the group.

$ ssh ddecker@host  
Last login: Thu Dec 12 17:42:37 2013  
[ddecker@host ~]$

As you can see above, I can SSH into it using SSH keys with no issues. However, no matter what command I run with Ansible, it just hangs and I have to CTL+C it to get it to come back. When I do, Python spits out some stuff:

$ ansible host -u ddecker -s -m raw -a “ls”  
Traceback (most recent call last):  
File “/home/ddecker/ansible/bin/ansible”, line 157, in   
(runner, results) = cli.run(options, args)  
File “/home/ddecker/ansible/bin/ansible”, line 131, in run  
results = runner.run()  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 992, in run  
results = [self.\_executor(h, None) for h in hosts]  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 394, in \_executor  
exec\_rc = self.\_executor\_internal(host, new\_stdin)  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 485, in \_executor\_internal  
return self.\_executor\_internal\_inner(host, self.module\_name, self.module\_args, inject, port, complex\_args=complex\_args)  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 685, in \_executor\_internal\_inner  
result = handler.run(conn, tmp, module\_name, module\_args, inject, complex\_args)  
File “/home/ddecker/ansible/lib/ansible/runner/action\_plugins/raw.py”, line 47, in run  
result=self.runner.\_low\_level\_exec\_command(conn, module\_args, tmp, sudoable=True, executable=executable)  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 771, in \_low\_level\_exec\_command  
rc, stdin, stdout, stderr = conn.exec\_command(cmd, tmp, sudo\_user, sudoable=sudoable, executable=executable)  
File “/home/ddecker/ansible/lib/ansible/runner/connection\_plugins/ssh.py”, line 221, in exec\_command  
rfd, wfd, efd = select.select(rpipes, , rpipes, 1)  
KeyboardInterrupt

Not sure why this is happening - could someone give me some sort of idea on what else I can do to help provide some sort of fix to this issue?

Thanks,  
Drew

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [December 13, 2013, 2:18am UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/2 "2013-12-13T02:18:19Z")

</div>

try running without -s (that forces sudo and might be the issue here).

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [December 13, 2013, 2:18am UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/3 "2013-12-13T02:18:42Z")

</div>

also -vvv is helpful when debugging.

---

<div class="post-metadata">

**Author:** ![Drew\_Decker](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Drew\_Decker](https://forum.ansible.com/u/Drew_Decker)\
**Post date:** [December 13, 2013, 3:04am UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/4 "2013-12-13T03:04:13Z")

</div>

I don’t get much with “-vvv” and I’ve also removed “-s”:

It still hangs and this is the output (after several minutes of waiting for it to do something):

$ ansible host -u ddecker -m raw -a “ls” -vvvv  
 ESTABLISH CONNECTION FOR USER: ddecker  
 EXEC [‘ssh’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/home/ddecker/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, ‘host’, ‘ls’]

Traceback (most recent call last):  
File “/home/ddecker/ansible/bin/ansible”, line 157, in   
(runner, results) = cli.run(options, args)  
File “/home/ddecker/ansible/bin/ansible”, line 131, in run  
results = runner.run()  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 992, in run  
results = [self.\_executor(h, None) for h in hosts]  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 394, in \_executor  
exec\_rc = self.\_executor\_internal(host, new\_stdin)  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 485, in \_executor\_internal  
return self.\_executor\_internal\_inner(host, self.module\_name, self.module\_args, inject, port, complex\_args=complex\_args)  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 685, in \_executor\_internal\_inner  
result = handler.run(conn, tmp, module\_name, module\_args, inject, complex\_args)  
File “/home/ddecker/ansible/lib/ansible/runner/action\_plugins/raw.py”, line 47, in run  
result=self.runner.\_low\_level\_exec\_command(conn, module\_args, tmp, sudoable=True, executable=executable)  
File “/home/ddecker/ansible/lib/ansible/runner/ **init**.py”, line 771, in \_low\_level\_exec\_command  
rc, stdin, stdout, stderr = conn.exec\_command(cmd, tmp, sudo\_user, sudoable=sudoable, executable=executable)  
File “/home/ddecker/ansible/lib/ansible/runner/connection\_plugins/ssh.py”, line 221, in exec\_command  
rfd, wfd, efd = select.select(rpipes, , rpipes, 1)  
KeyboardInterrupt

---

<div class="post-metadata">

**Author:** ![Drew\_Decker](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Drew\_Decker](https://forum.ansible.com/u/Drew_Decker)\
**Post date:** [December 13, 2013, 3:38pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/5 "2013-12-13T15:38:43Z")

</div>

So, it appears that I’ve figured it out - but don’t really understand why exactly. As you can see from my previous threads that I was able to SSH into the host, but Ansible just wouldn’t return anything for a random host, correct? Another thing I noticed was it was also a bit slow. In our environment, we have about 4 main domains, for different locations. In the /etc/resolv.conf file, we have search domains defined so we can use the short hostnames that are in DNS. This doesn’t appear to have any issues whatsoever, except sometimes in Ansible; not sure why.

What I ended up doing was adding the FQDN into the /etc/ansible/hosts file to each host, and when I did that I got a HUGE performance increase and I also no longer run into this problem.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 13, 2013, 3:41pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/6 "2013-12-13T15:41:27Z")

</div>

What was in the hosts file prior to the FQDNs ?

---

<div class="post-metadata">

**Author:** ![Drew\_Decker](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Drew\_Decker](https://forum.ansible.com/u/Drew_Decker)\
**Post date:** [December 13, 2013, 3:44pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/7 "2013-12-13T15:44:05Z")

</div>

Just to short hostnames.

**Prior to FQDN:**

host1  
host2  
host3

(resolv.conf had the search domains) - regular SSHing into machines worked, but ansible was either slow or never returned a value on “-m ping”.

**After adding FQDN:**

[host1.domain.com](http://host1.domain.com)  
[host2.domain.com](http://host2.domain.com)  
[host3.domain.com](http://host3.domain.com)

(resolv.conf still has the search domains, but aren’t needed for Ansible now because I’m using the FQDN) - huge performance increase and no more failures.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 13, 2013, 3:52pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/8 "2013-12-13T15:52:41Z")

</div>

Sounds like you have sketchy DNS then?

Might want to look into that…

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 13, 2013, 3:56pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/9 "2013-12-13T15:56:13Z")

</div>

Having the search domains and nameservers in resolv.conf in an optimal order should also help in this case.

---

<div class="post-metadata">

**Author:** ![Drew\_Decker](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Drew\_Decker](https://forum.ansible.com/u/Drew_Decker)\
**Post date:** [December 13, 2013, 3:56pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/10 "2013-12-13T15:56:36Z")

</div>

We do not - because like I said - regular SSH is working. I can do anything with the regular hostnames with anything such as regular hostnames, applications, SNMP, backups, etc. I think it might be an issue with something either in Ansible (i doubt its Ansible directly) or (more than likely) possibly a python dependency such as paramiko (since it appears that that’s the module that is actually performing the SSH. When I can run all system servers without the FQDN but I have weird issues with a single application, then I’m more than likely going to blame that single applications, as I would be having a lot more issues across the entire environment.

---

<div class="post-metadata">

**Author:** ![Drew\_Decker](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Drew\_Decker](https://forum.ansible.com/u/Drew_Decker)\
**Post date:** [December 13, 2013, 3:57pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/11 "2013-12-13T15:57:51Z")

</div>

Yup this has been done - we have the Ansible “Control Node”’s search domain first, and then the other environments next, however, it doesn’t get any more configurable than than unfortunately.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 13, 2013, 4:00pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/12 "2013-12-13T16:00:26Z")

</div>

Are the speeds between -c paramiko and -c ssh similar or is there a drastic difference (shortnames in hosts file) ?

---

<div class="post-metadata">

**Author:** ![Drew\_Decker](https://avatars.discourse-cdn.com/v4/letter/d/6f9a4e/32.png) [@Drew\_Decker](https://forum.ansible.com/u/Drew_Decker)\
**Post date:** [December 13, 2013, 4:11pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/13 "2013-12-13T16:11:09Z")

</div>

Oh wow - yup there’s a huge difference. When I type “-c ssh” its REALLY fast, and I get no errors at all.

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [December 13, 2013, 4:23pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/14 "2013-12-13T16:23:37Z")

</div>

So this is really seems to be a paramiko DNS performance issue in your case.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [December 14, 2013, 7:03pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/15 "2013-12-14T19:03:09Z")

</div>

I always add “usedns no” to my sshd\_config for this reason.

Brian Coca

---

<div class="post-metadata">

**Author:** ![Lars\_Hansson](https://avatars.discourse-cdn.com/v4/letter/l/8edcca/32.png) [@Lars\_Hansson](https://forum.ansible.com/u/Lars_Hansson)\
**Post date:** [December 15, 2013, 6:11pm UTC](https://forum.ansible.com/t/issues-with-connecting-to-a-host/14147/16 "2013-12-15T18:11:39Z")

</div>

I also set  
KerberosAuthentication no  
GSSAPIAuthentication no

Both have a tendency to use DNS and slow things down.
