Dynamic inventory cache

343 views
Skip to first unread message

André Cruz

unread,
May 24, 2016, 12:55:46 PM5/24/16
to Ansible Project
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é

Matt Hite

unread,
May 24, 2016, 5:39:39 PM5/24/16
to ansible...@googlegroups.com
I believe it would be up to the dynamic inventory script to implement the caching functionality.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2bb40eb4-a75d-4280-9332-8faa2f060fba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

André Cruz

unread,
May 26, 2016, 10:30:25 AM5/26/16
to ansible...@googlegroups.com
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 received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/4_UxdmUx3vQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFOdRHJhtKDn%3DQ%3DbAsCi2V_bxnaK8a49PiMBqeOFiTaR%2B6fTYQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
André Cruz

Brian Coca

unread,
May 26, 2016, 10:40:58 AM5/26/16
to ansible...@googlegroups.com
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.

On Thu, May 26, 2016 at 10:30 AM, André Cruz <andre...@gmail.com> wrote:
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...

----------
Brian Coca

André Cruz

unread,
Jun 1, 2016, 8:22:22 AM6/1/16
to Ansible Project

On Thursday, May 26, 2016 at 3:40:58 PM UTC+1, Brian Coca wrote:
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é

Brian Coca

unread,
Jun 1, 2016, 9:29:15 AM6/1/16
to ansible...@googlegroups.com
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.

----------
Brian Coca

Guillermo Di Pasquale

unread,
Jun 18, 2018, 3:58:41 AM6/18/18
to Ansible Project
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!

J Hawkesworth

unread,
Jun 19, 2018, 6:18:08 AM6/19/18
to Ansible Project
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

Brian Coca

unread,
Jun 19, 2018, 11:53:29 AM6/19/18
to Ansible Project
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).




--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages