# Ansible Dyn inventory speed issue

**URL:** <https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366>\
**Category:** Ansible Developer\
**Created:** [May 1, 2017, 6:18pm UTC](https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366 "2017-05-01T18:18:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris4](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chris4](https://forum.ansible.com/u/chris4)\
**Post date:** [May 1, 2017, 6:18pm UTC](https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366/1 "2017-05-01T18:18:58Z")

</div>

Hi,

I’m having issues with a dynamic inventory script I created for Solar Winds. It’s here, [https://github.com/cbabs/solarwinds-ansible-inv](https://github.com/cbabs/solarwinds-ansible-inv). The script seems to work as expected. When I copy to hosts and run with --list seems fine. It takes a few seconds to query the Orion SQL server via rest and return the data. However when I execute “ansible --list-hosts all” it’s very slow. I tried with the dyn inv script as ‘hosts’ and with a static hosts file with the same data. Clearly I don’t understand something.

It’s almost like Ansible is iterating it’s process on each entry instead of reading all the output at once. I’ve read the “Developing Dynamic Inventory Sources” doc three times looking a for something I missed. I don’t get it.

Here are my results:

Command with dynamic inventory 406 hosts:

**_Command being timed: “/usr/bin/ansible --list-hosts all”_**

**_User time (seconds): 23.25_**

**_System time (seconds): 3.73_**

**_Percent of CPU this job got: 9%_**

**_Elapsed (wall clock) time (h:mm:ss or m:ss): 4:36.02_**

**_Average shared text size (kbytes): 0_**

**_Average unshared data size (kbytes): 0_**

**_Average stack size (kbytes): 0_**

**_Average total size (kbytes): 0_**

**_Maximum resident set size (kbytes): 32004_**

**_Average resident set size (kbytes): 0_**

**_Major (requiring I/O) page faults: 0_**

**_Minor (reclaiming a frame) page faults: 2814913_**

**_Voluntary context switches: 13044_**

**_Involuntary context switches: 13365_**

**_Swaps: 0_**

**_File system inputs: 0_**

**_File system outputs: 248_**

**_Socket messages sent: 0_**

**_Socket messages received: 0_**

**_Signals delivered: 0_**

**_Page size (bytes): 4096_**

**_Exit status: 0_**

Command with Static inventory 406 hosts:

_ **Command being timed: “/usr/bin/ansible --list-hosts all”** _

_**User time (seconds): 0.60**_

_**System time (seconds): 0.04**_

_ **Percent of CPU this job got: 89%** _

_**Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.72**_

_**Average shared text size (kbytes): 0**_

_**Average unshared data size (kbytes): 0**_

_**Average stack size (kbytes): 0**_

_**Average total size (kbytes): 0**_

_**Maximum resident set size (kbytes): 31832**_

_**Average resident set size (kbytes): 0**_

_**Major (requiring I/O) page faults: 0**_

_**Minor (reclaiming a frame) page faults: 52876**_

_ **Voluntary context switches: 367** _

_ **Involuntary context switches: 1115** _

_ **Swaps: 0** _

_ **File system inputs: 0** _

_ **File system outputs: 248** _

_ **Socket messages sent: 0** _

_ **Socket messages received: 0** _

_ **Signals delivered: 0** _

_**Page size (bytes): 4096**_

_ **Exit status: 0** _

Thanks,

Chris

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 1, 2017, 6:21pm UTC](https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366/2 "2017-05-01T18:21:42Z")

</div>

It’s likely you are not including `_meta` to support the needs of ansible.

See [https://github.com/ansible/ansible/pull/24085](https://github.com/ansible/ansible/pull/24085)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 1, 2017, 6:23pm UTC](https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366/3 "2017-05-01T18:23:29Z")

</div>

I looked at the source and it only supplies `_meta` when the inventory  
is empty, this causes ansible to re-execute the script once per host  
with the `--host` option.

Update the script to supply the host vars inside the `_meta` key and  
that should speed up the inventory.

---

<div class="post-metadata">

**Author:** ![chris4](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@chris4](https://forum.ansible.com/u/chris4)\
**Post date:** [May 1, 2017, 8:56pm UTC](https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366/4 "2017-05-01T20:56:01Z")

</div>

Yup! Thanks for the help Brian and Matt. Much appreciated.

Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Babcock](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chris\_Babcock](https://forum.ansible.com/u/Chris_Babcock)\
**Post date:** [May 1, 2017, 9:02pm UTC](https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366/5 "2017-05-01T21:02:41Z")

</div>

Seems to be working well now. What is the process to submit to Ansible?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 1, 2017, 9:35pm UTC](https://forum.ansible.com/t/ansible-dyn-inventory-speed-issue/24366/6 "2017-05-01T21:35:20Z")

</div>

Open pull request against [https://github.com/ansible/ansible](https://github.com/ansible/ansible)
