# ansible cmd run takes over 40s per server

**URL:** <https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780>\
**Category:** Ansible Project\
**Tags:** fedora\
**Created:** [March 14, 2014, 11:50pm UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780 "2014-03-14T23:50:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filip\_Slunecko](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Filip\_Slunecko](https://forum.ansible.com/u/Filip_Slunecko)\
**Post date:** [March 14, 2014, 11:50pm UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/1 "2014-03-14T23:50:30Z")

</div>

Hi,

I installed a fresh Ansible from git hub on CentOS 6.3 and run a simple command takes over 40s with CPU 100% for Ansible.

This is a line from cProfile([http://pastebin.com/mX4qXsiN](http://pastebin.com/mX4qXsiN)).

11523 40.093 0.003 54.893 0.005 hostkeys.py:181(lookup)

It seems to that Ansible is doing a lot of lookups.  
The same version works on my box without an issue(Fedora 20).

Command:  
ansible/bin/ansible XXX -u root --private-key /root/.ssh/id\_rsa -i inventory/ -m shell -a echo test -vvv

I ran Ansible on CentOS 6.3 boxes and I’ve never seen like this before.

Thanks

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 15, 2014, 12:00am UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/2 "2014-03-15T00:00:31Z")

</div>

This is pretty unusual.

This is a function inside the paramiko source code that does not (at least obviously does not) do anything like DNS lookups.

I’m at a bit of a loss, perhaps you can debug further?

Fedora 20 has a new enough SSH so the default connection type is “ssh” not paramiko there, curious if you have the same with “-c paramiko” on that box (and using the same key?)

---

<div class="post-metadata">

**Author:** ![Filip\_Slunecko](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Filip\_Slunecko](https://forum.ansible.com/u/Filip_Slunecko)\
**Post date:** [March 15, 2014, 12:14am UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/3 "2014-03-15T00:14:06Z")

</div>

ansible XX -c paramiko -u root --private-key .ssh/root\_id -i inventory/ -m shell -a echo test

it’s fast on F20.

We have a big /etc/hosts file (1527 hosts), but I copied the host file to my box and it doesn’t make a difference.

---

<div class="post-metadata">

**Author:** ![Filip\_Slunecko](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Filip\_Slunecko](https://forum.ansible.com/u/Filip_Slunecko)\
**Post date:** [March 15, 2014, 12:36am UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/4 "2014-03-15T00:36:18Z")

</div>

I deployed on different box (the same version) and it works just fine.  
Not sure what is the issue on the first one.

---

<div class="post-metadata">

**Author:** ![adam2](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@adam2](https://forum.ansible.com/u/adam2)\
**Post date:** [March 15, 2014, 1:37am UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/5 "2014-03-15T01:37:56Z")

</div>

nscd turned off? ldap in use?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 15, 2014, 2:20pm UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/6 "2014-03-15T14:20:06Z")

</div>

Paramiko’s host file handling has been noted to be a performance problem in some cases where host files get large.

We haven’t exactly tracked down _why_.

(I really really wish RHEL/CentOS would update their OpenSSH… can’t wait for RHEL 7 – and less and less folks will need paramiko)

---

<div class="post-metadata">

**Author:** ![Filip\_Slunecko](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Filip\_Slunecko](https://forum.ansible.com/u/Filip_Slunecko)\
**Post date:** [March 26, 2014, 9:53pm UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/7 "2014-03-26T21:53:51Z")

</div>

So the reason is that my known\_hosts file has over 5k records.  
I think that Paramiko is for looping for each host in known\_hosts and /etc/hosts file.  
In my case it’s around 800k checks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 26, 2014, 11:34pm UTC](https://forum.ansible.com/t/ansible-cmd-run-takes-over-40s-per-server/14780/8 "2014-03-26T23:34:38Z")

</div>

Paramiko’s processing of known\_hosts is rather poor for large host files.

I’d recommend using the SSH transport if you can.
