# meta: refresh\_inventory to support conditions

**URL:** <https://forum.ansible.com/t/meta-refresh-inventory-to-support-conditions/23892>\
**Category:** Ansible Developer\
**Created:** [March 6, 2017, 1:10pm UTC](https://forum.ansible.com/t/meta-refresh-inventory-to-support-conditions/23892 "2017-03-06T13:10:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Yanev](https://avatars.discourse-cdn.com/v4/letter/g/d6d6ee/32.png) [@George\_Yanev](https://forum.ansible.com/u/George_Yanev)\
**Post date:** [March 6, 2017, 1:10pm UTC](https://forum.ansible.com/t/meta-refresh-inventory-to-support-conditions/23892/1 "2017-03-06T13:10:27Z")

</div>

Hi All,

We want to remove some duplicate code which is available in our custom Inventory as well as in Ansible Playbook.

meta: refresh\_inventory is what we need but it lacks conditional support. Is there a specific reason for this?

Looking at the code one possible solution will be to add \_evaluate\_conditional(target\_host) for the meta\_action == ‘refresh\_inventory’? I’m happy to create a PR for this functionality.

---

<div class="post-metadata">

**Author:** ![Kristiyan\_Nikolov](https://avatars.discourse-cdn.com/v4/letter/k/cab0a1/32.png) [@Kristiyan\_Nikolov](https://forum.ansible.com/u/Kristiyan_Nikolov)\
**Post date:** [March 11, 2017, 8:49pm UTC](https://forum.ansible.com/t/meta-refresh-inventory-to-support-conditions/23892/2 "2017-03-11T20:49:15Z")

</div>

Hi George,

There is a way to skip the refresh\_inventory meta action with dynamic include task statement.

All you have to do is:

1. Create new file, for example: refresh\_inventory.yml
2. Add include statement with argument static: no and your condition

This will resolve the ‘refresh\_inventory.yml’ just before it is included, but not at compile time.

You can check an example here: [https://gist.github.com/cnicolov/0969a99809ec58a9df26024297067c38](https://gist.github.com/cnicolov/0969a99809ec58a9df26024297067c38)

Regards,  
Kristiyan

понеделник, 6 март 2017 г., 15:10:28 UTC+2, George Yanev написа:

---

<div class="post-metadata">

**Author:** ![George\_Yanev](https://avatars.discourse-cdn.com/v4/letter/g/d6d6ee/32.png) [@George\_Yanev](https://forum.ansible.com/u/George_Yanev)\
**Post date:** [March 12, 2017, 12:10am UTC](https://forum.ansible.com/t/meta-refresh-inventory-to-support-conditions/23892/3 "2017-03-12T00:10:35Z")

</div>

Thanks Kristiyan. Tested your solution and it’s working.
