Ansible Dyn inventory speed issue

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. 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

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

See https://github.com/ansible/ansible/pull/24085

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.

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

Chris

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

Open pull request against https://github.com/ansible/ansible