# Ansible to manipulate dynamic inventory

**URL:** <https://forum.ansible.com/t/ansible-to-manipulate-dynamic-inventory/19551>\
**Category:** Ansible Project\
**Created:** [October 19, 2015, 8:18pm UTC](https://forum.ansible.com/t/ansible-to-manipulate-dynamic-inventory/19551 "2015-10-19T20:18:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bence\_Takacs](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@Bence\_Takacs](https://forum.ansible.com/u/Bence_Takacs)\
**Post date:** [October 19, 2015, 8:18pm UTC](https://forum.ansible.com/t/ansible-to-manipulate-dynamic-inventory/19551/1 "2015-10-19T20:18:37Z")

</div>

Upon running some tasks I need to manipulate Ansible host variables.

I created a dynamic inventory script that could support thata functionality and then I stucked:

- inventory modules support only add\_host which works only in-memory
- I see no sign that ansible is capable of doing this: everything points to inventory providers like Tower, EC2, vagrant and Cobbler
- I found one suggestion to handle inventory manipulation outside ansible

I can create a solution that could handle the new parameters in-memory and then call my inventory script and update it at the end of playbook run. But I’m thinking: is it so weird idea?  
Why haven’t it designed this way? Or am I missing something?

---

<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:** [October 19, 2015, 9:05pm UTC](https://forum.ansible.com/t/ansible-to-manipulate-dynamic-inventory/19551/2 "2015-10-19T21:05:27Z")

</div>

Well, normally you start with either already existing hosts that you  
can list in inventory or a virtualization solution (including clouds)  
which normally already have a dynamically updated DB with the list of  
the machines, add\_hosts is only in memory because the inventory  
scripts are not normally 'refreshed' in the middle of a run, the  
expectation is that the subsequent runs would automatically retrieve  
the new hosts form the existing 'source of truth'.

In 2.0 we've added `meta: refresh_inventory` that can force the  
dynamic inventory update in the middle of play.
