Dynamic inventory cache

Hello all.

I’m using the Azure RM dynamic inventory script, which although it works fine, is very slow.

Is it possible to cache its results and reuse them on another invocation? Can I just dump the output of the script (JSON) and load it?

Thank you and best regards,
André

I believe it would be up to the dynamic inventory script to implement the caching functionality.

Since ansible already supports caching of facts shouldn’t this also be a job of ansible itself? Otherwise each dynamic inventory plugin will implement it in a different way or not implement it at all…

You’ve hit the nail on the head! We do have plans to make a ‘inventory cache’ part of Ansible itself, currently its up to each script and of course we have different implementations and some that don’t implement any.

You’ve hit the nail on the head! We do have plans to make a ‘inventory cache’ part of Ansible itself, currently its up to each script and of course we have different implementations and some that don’t implement any.

While we don’t have a global inventory cache, I’m saving the dynamic inv script output to a file, and using it between ansible runs. In order for this to work I have a hack which is an executable script that the only thing it does it “cat output.json”. Is there a better way? Can ansible read directly the hosts from the json file or ir there a way to convert this json to the format ansible understands?

Thanks,
André

in 2.1 ansible supports a yaml inventory file format, this can read json but the format is not the same as the ‘dynamic script’ output.

Hi folks,

This is an old thread, but has this support been added to inventory script? My initial testing indicates that it is not doing any caching, but perhaps I’m missing a setting. I added in my .ansible.cfg the following:

[inventory_plugin_script]
cache=yes

However, I don’t see the inventory being cached at all.

Thanks!

I believe inventory plugins will allow use of ansible internals, which could including caching, if configured.

The existing inventory scripts won’t be able to do this though.

See https://docs.ansible.com/ansible/2.5/plugins/inventory.html for information about which inventory plugins are available.

Jon

This is a bug, the 'inventory cache' was originally added in 2.4 but
we had to remove it due to some issues. We have added it back in 2.5
but forgot to update the script plugin to handle it also (or just
remove the docs that says it is supported).