# Output a dynamic inventory

**URL:** <https://forum.ansible.com/t/output-a-dynamic-inventory/14817>\
**Category:** Ansible Project\
**Created:** [March 20, 2014, 11:16pm UTC](https://forum.ansible.com/t/output-a-dynamic-inventory/14817 "2014-03-20T23:16:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juergen\_Brendel](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Juergen\_Brendel](https://forum.ansible.com/u/Juergen_Brendel)\
**Post date:** [March 20, 2014, 11:16pm UTC](https://forum.ansible.com/t/output-a-dynamic-inventory/14817/1 "2014-03-20T23:16:28Z")

</div>

Hello!

I have a playbook, which dynamically creates hosts on Amazon EC2 and (also dynamically) adds them to various groups.

Ideally, I would like to be able to revisit these hosts on a second run, just in case something went wrong with one of those hosts, or I want to change something.

Therefore, I’m wondering if there is a preferred way to output (dump) the current state of the dynamic inventory. Is there a module for it or do I have to use a local\_action, run my groups through a template and generate an inventory file in that manner?

Thank you for your help…

---

<div class="post-metadata">

**Author:** ![Jesse\_Keating](https://avatars.discourse-cdn.com/v4/letter/j/3bc359/32.png) [@Jesse\_Keating](https://forum.ansible.com/u/Jesse_Keating)\
**Post date:** [March 21, 2014, 5:24am UTC](https://forum.ansible.com/t/output-a-dynamic-inventory/14817/2 "2014-03-21T05:24:58Z")

</div>

I don't believe there is a built in way to do what you want. A local\_action with a template is the way to go.

-jlk

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 21, 2014, 1:05pm UTC](https://forum.ansible.com/t/output-a-dynamic-inventory/14817/3 "2014-03-21T13:05:58Z")

</div>

"  
Ideally, I would like to be able to revisit these hosts on a second run, just in case something went wrong with one of those hosts,"

The way to do this is to call some basic script tests to verify that your service is running by the time your playbooks complete, such that the playbooks fail for those hosts.

Then the generated retry file can be used to selectively target just the hosts that fail.

---

<div class="post-metadata">

**Author:** ![Juergen\_Brendel](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Juergen\_Brendel](https://forum.ansible.com/u/Juergen_Brendel)\
**Post date:** [March 21, 2014, 9:47pm UTC](https://forum.ansible.com/t/output-a-dynamic-inventory/14817/4 "2014-03-21T21:47:24Z")

</div>

Hello!

> The way to do this is to call some basic script tests to verify that  
> your service is running by the time your playbooks complete, such that  
> the playbooks fail for those hosts.
> 
> Then the generated retry file can be used to selectively target just  
> the hosts that fail.

Yes, that would work. Thank you for your response.

In the meantime, I've gone the route of generating a full inventory file  
via a template. Fortunately, that's easy enough. That way, I can use  
this inventory also for further configuration management tasks for which  
maybe I have other playbooks.

Thank you again...

Juergen
