# run a specific task sequentially for each host

**URL:** <https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421>\
**Category:** Ansible Project\
**Created:** [January 24, 2014, 8:29pm UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421 "2014-01-24T20:29:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack1](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@jack1](https://forum.ansible.com/u/jack1)\
**Post date:** [January 24, 2014, 8:29pm UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/1 "2014-01-24T20:29:45Z")

</div>

Hi, All:

The serial: 1 allows us to run a play sequentially for each host in the host group. But we cannot find similar setting at task level. We want to find a way to run a task in a role sequentially for each host because some external racing issue. Anyone knows how to do it?

Thanks  
Jack

---

<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:** [January 24, 2014, 8:36pm UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/2 "2014-01-24T20:36:47Z")

</div>

" We want to find a way to run a task in a role sequentially for each host because some external racing issue. Anyone knows how to do it?"

If this means one host at a time, set up a mini-play with just that task and set “serial: 1” on that play.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [January 24, 2014, 9:33pm UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/3 "2014-01-24T21:33:41Z")

</div>

​I too sometimes wished this could be triggered at task level​, so it can  
be defined at role level.  
One of my use cased would then be to use it in a handler (which is just a  
special task) to avoid race conditions when run on the same delegated host.

Wouldn't this be something?

&nbsp;&nbsp;&nbsp;Serge

---

<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:** [January 25, 2014, 12:07am UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/4 "2014-01-25T00:07:06Z")

</div>

So, rather than serial: 1 at a task level (this is a bit of a complex thing), what I really want is the equivalent of the BYPASS\_HOST\_LOOP code that the pause module uses to be used at a language level also.

Basically thus:

- module\_foo: blah

- local\_action\_once: module blah

- module\_baz: blah

I don’t think it would make much sense out of a local action.

In the other case, I do believe it should be a seperate play to reuse the existing functionality and make it more explicit.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [January 25, 2014, 12:17am UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/5 "2014-01-25T00:17:01Z")

</div>

​I'm not sure. Why?

I see this more in case of delegated tasks. Local is just a delegate to  
localhost, isn't it?

&nbsp;&nbsp;Serge​

---

<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:** [January 25, 2014, 1:05am UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/6 "2014-01-25T01:05:41Z")

</div>

Because it would have to pick a single host arbitrarily.

Shorthand for “only execute on the headnode of a cluster?”

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [January 25, 2014, 12:52pm UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/7 "2014-01-25T12:52:19Z")

</div>

> Because it would have to pick a single host arbitrarily.

Isn't that the same problem of picking which node's hostvars to use when  
running locally just once?​​

Shorthand for "only execute on the headnode of a cluster?"

> 

Yes, that's basically it I think. Would be a nice feature.

Serge

---

<div class="post-metadata">

**Author:** ![jack1](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@jack1](https://forum.ansible.com/u/jack1)\
**Post date:** [February 3, 2014, 10:55pm UTC](https://forum.ansible.com/t/run-a-specific-task-sequentially-for-each-host/14421/8 "2014-02-03T22:55:20Z")

</div>

Hi, Michael:

We separated the play, and use serial: 1 for the task which we want to run at one host per time. But we observed that if first node at this task fails, then all the other nodes will not be ran anymore. and also it only reports the failure for the first node, for all other nodes, even though the task is not performed, ansible still reports succeeded.

Something like:

test01 : ok=12 changed=0 unreachable=0 failed=0  
test02 : ok=14 changed=1 unreachable=0 failed=1

Thanks  
Jack
