ansible-plugin icon indicating copy to clipboard operation
ansible-plugin copied to clipboard

Dynamic inventory rescan consuming lots of cpu resources

Open msperl opened this issue 6 years ago • 2 comments

The rescan of the inventory is taking quite some time on bigger inventories and is consuming all cpus running multiple ansible processes concurrently (probably just using to_json to dump the variables)

For our inventory of 500 hosts this takes almost 10 minutes every hour

Is there a way to optimize this?

Possibly solution: maybe use ansible-inventory - see #223

msperl avatar Apr 07 '19 06:04 msperl

Hello @msperl !

I am not sure if this gonna help you but you can use redis to cache gathering facts from your host. Just check ansible official documentation, its super easy : https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#fact-caching

Another options is to increase forks in ansible.cfg file : https://docs.ansible.com/ansible/2.4/intro_configuration.html#forks

I hope this will help! Cheers!

Slapper avatar May 05 '19 07:05 Slapper

Unfortunately this does not help, as it is related to the fact that the ansible-script that is running to gather all the infos src/main/resources/gather-hosts.yml (even when fact gathering is disabled) needs to process: src/main/resources/host-tpl.j2 for all of those 500 hosts is consuming is consuming lots of CPU cycles.

I found out that the concurrency is controllable by setting forks in ansible.conf to a lower value.

But obviously this impacts ALL ansible scripts and not just the discovery portion.

So a means to configure forks for gathering host info separately is all that is needed.

More generally when fact gathering is disabled, then maybe using the output of ansible-inventory --list may be a more efficient alternative.

When fact_caching is enabled and facts have been gathered by another means, then I believe that ansible-inventory will dump everything if requested to do so (unfortunately I can not confirm this at this very moment)

So on could avoid this overhead in the first place and just use ansible-inventory (for versions that have it)

msperl avatar May 10 '19 15:05 msperl