# How to handle case when dynamic inventory initially returns empty host list?

**URL:** <https://forum.ansible.com/t/how-to-handle-case-when-dynamic-inventory-initially-returns-empty-host-list/29694>\
**Category:** Ansible Project\
**Created:** [February 16, 2019, 3:24pm UTC](https://forum.ansible.com/t/how-to-handle-case-when-dynamic-inventory-initially-returns-empty-host-list/29694 "2019-02-16T15:24:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei\_Pashkin](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Andrei\_Pashkin](https://forum.ansible.com/u/Andrei_Pashkin)\
**Post date:** [February 16, 2019, 3:24pm UTC](https://forum.ansible.com/t/how-to-handle-case-when-dynamic-inventory-initially-returns-empty-host-list/29694/1 "2019-02-16T15:24:13Z")

</div>

Let’s suppose I have a custom dynamic inventory fetches instances from EC2 and makes an inventory from them and then if certain required instances do not exist they are created in the playbook and then inventory is refreshed using “meta: refresh\_inventory” task.

My problem is that when initial inventory is empty (because there is no instances at all) - Ansible just stops.

I wonder - is there a recommended idiom to solve such problem?

---

<div class="post-metadata">

**Author:** ![Keif\_Gwinn1](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@Keif\_Gwinn1](https://forum.ansible.com/u/Keif_Gwinn1)\
**Post date:** [February 18, 2019, 10:55am UTC](https://forum.ansible.com/t/how-to-handle-case-when-dynamic-inventory-initially-returns-empty-host-list/29694/2 "2019-02-18T10:55:01Z")

</div>

Perhaps add a static inventory item alongside the dynamic so the scripts can run against ansible localhost to create the remote inventory?

[https://www.linuxtechi.com/manage-ansible-static-and-dynamic-host-inventory/](https://www.linuxtechi.com/manage-ansible-static-and-dynamic-host-inventory/)

[http://allandenot.com/devops/2015/01/16/ansible-with-multiple-inventory-files.html](http://allandenot.com/devops/2015/01/16/ansible-with-multiple-inventory-files.html)
