# Dynamic inventory cache

**URL:** <https://forum.ansible.com/t/dynamic-inventory-cache/21547>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [May 24, 2016, 4:55pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547 "2016-05-24T16:55:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andre\_Cruz](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@Andre\_Cruz](https://forum.ansible.com/u/Andre_Cruz)\
**Post date:** [May 24, 2016, 4:55pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/1 "2016-05-24T16:55:46Z")

</div>

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é

---

<div class="post-metadata">

**Author:** ![Matt\_Hite](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Matt\_Hite](https://forum.ansible.com/u/Matt_Hite)\
**Post date:** [May 24, 2016, 9:39pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/2 "2016-05-24T21:39:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andre\_Cruz](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@Andre\_Cruz](https://forum.ansible.com/u/Andre_Cruz)\
**Post date:** [May 26, 2016, 2:30pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/3 "2016-05-26T14:30:14Z")

</div>

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…

---

<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 26, 2016, 2:40pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/4 "2016-05-26T14:40:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andre\_Cruz](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@Andre\_Cruz](https://forum.ansible.com/u/Andre_Cruz)\
**Post date:** [June 1, 2016, 12:22pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/5 "2016-06-01T12:22:22Z")

</div>

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

---

<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:** [June 1, 2016, 1:29pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/6 "2016-06-01T13:29:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Guillermo\_Di\_Pasqual](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@Guillermo\_Di\_Pasqual](https://forum.ansible.com/u/Guillermo_Di_Pasqual)\
**Post date:** [June 18, 2018, 7:58am UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/7 "2018-06-18T07:58:41Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 19, 2018, 10:18am UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/8 "2018-06-19T10:18:07Z")

</div>

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](https://docs.ansible.com/ansible/2.5/plugins/inventory.html) for information about which inventory plugins are available.

Jon

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 19, 2018, 3:53pm UTC](https://forum.ansible.com/t/dynamic-inventory-cache/21547/9 "2018-06-19T15:53:17Z")

</div>

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