# New 1.2 feature, retrying only hosts with failures

**URL:** <https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646>\
**Category:** Ansible Project\
**Created:** [April 8, 2013, 3:57am UTC](https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646 "2013-04-08T03:57:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 8, 2013, 3:57am UTC](https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646/1 "2013-04-08T03:57:05Z")

</div>

It is sometimes nice to be able to run actions on hosts that previously encountered failures.

Now, in 1.2 (just now), you get a message like this when you have failures:

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to rerun against failed hosts, use -i /etc/ansible/.foo.yml.retry

[a.example.com](http://a.example.com) : ok=2 changed=0 unreachable=0 failed=0

[b.example.com](http://b.example.com) : ok=1 changed=0 unreachable=0 failed=1  
…

Want to target just those hosts when re-running the same playbook or doing something else?

You can.

ansible all -a “/sbin/reboot” -i /etc/ansible/.foo.yml.retry

The filename used for the retry file is predictable, it’s always derived from the name of the playbook and is put in your inventory directory (so group\_vars and host\_vars still work as expected).

Note: you may ask why it didn’t just pass “–limit” in instead of using “-i”, well, it could, but what if --limit was already set? Also, the number of hosts in the limit could get very large, so I didn’t like the idea of having to pass in 500 hosts via --limit since that command would look rather ugly. Also using “-i” means you can edit the inventory if you really really want to.

Minor caveat: you must have permissions to write to your inventory directory for this feature to be used.

I hope this allows for some very easy re-runs on playbook content on failed hosts, as well as some new use cases of other varieties.

There may be some minor kinks in this (maybe around child groups or something) but it seems pretty reasonable. Let me know if you encounter any problems, or have questions.

–Michael

---

<div class="post-metadata">

**Author:** ![Benjamin\_Ritcey](https://avatars.discourse-cdn.com/v4/letter/b/e495f1/32.png) [@Benjamin\_Ritcey](https://forum.ansible.com/u/Benjamin_Ritcey)\
**Post date:** [April 8, 2013, 3:53pm UTC](https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646/2 "2013-04-08T15:53:36Z")

</div>

Very cool, but need write perms to the inventory directory is kinda gross & wouldn’t work with many setups (I suspect) - any technical barriers to moving that to something like /var/tmp/ansible/?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 8, 2013, 4:18pm UTC](https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646/3 "2013-04-08T16:18:22Z")

</div>

I thought of a newer implemntation idea over breakfast.

–limit @limitfile

where we let --limit get loaded from a file, and we just write the lists of failed hosts.

I’ll make it work like that.

---

<div class="post-metadata">

**Author:** ![fdavis](https://avatars.discourse-cdn.com/v4/letter/f/a698b9/32.png) [@fdavis](https://forum.ansible.com/u/fdavis)\
**Post date:** [April 10, 2013, 5:37pm UTC](https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646/4 "2013-04-10T17:37:17Z")

</div>

Wow, thanks!

Hmm… I think this idea might fit better with ansible-commander,  
but what about having a way to re-run with this inventory after the playbook is done?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 15, 2013, 12:15am UTC](https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646/5 "2013-04-15T00:15:46Z")

</div>

Sorry for the late response.

I’m not sure you would want to automatically retry enough for ansible or acom to have a way to make that automatic, however, you could key off the return code for ansible if you wanted to do this.

I think it would be better to support retries on individual tasks though if that is what you were going for?

Maybe I don’t understand the use case fully.

---

<div class="post-metadata">

**Author:** ![PJ1](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@PJ1](https://forum.ansible.com/u/PJ1)\
**Post date:** [April 23, 2013, 8:18am UTC](https://forum.ansible.com/t/new-1-2-feature-retrying-only-hosts-with-failures/12646/6 "2013-04-23T08:18:12Z")

</div>

I agree with this. /etc is for configuration files only, if following the standard. Better to put it in /tmp or /var/tmp.
