# run\_once and serial

**URL:** <https://forum.ansible.com/t/run-once-and-serial/15778>\
**Category:** Ansible Project\
**Created:** [July 25, 2014, 2:08pm UTC](https://forum.ansible.com/t/run-once-and-serial/15778 "2014-07-25T14:08:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [July 25, 2014, 2:08pm UTC](https://forum.ansible.com/t/run-once-and-serial/15778/1 "2014-07-25T14:08:59Z")

</div>

I'm testing out the new run\_once feature and overall it's working  
great. But I then tried it in an upgrade playbook using serial. The  
task is no longer run just once per-play, it's run once  
per-host-group. So for a serial of 2 in a target group of 10 servers  
it's run once per pair, so 5 times.

This seems like a bug to me, but I just wanted to make sure before I  
filed a ticket on it.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [July 25, 2014, 6:25pm UTC](https://forum.ansible.com/t/run-once-and-serial/15778/2 "2014-07-25T18:25:09Z")

</div>

Yeah go ahead and open an issue for this, as it should only run once no matter what.

Thanks!

---

<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:** [July 25, 2014, 7:29pm UTC](https://forum.ansible.com/t/run-once-and-serial/15778/3 "2014-07-25T19:29:59Z")

</div>

It will probably just be easiest to make it an error to use run\_once with serial, because I don’t want to have to pass a parameter to runner like “run\_once\_has\_ran” and keep an internal hash for this.

In your case, solve the problem by having another play for the “run\_once” steps outside of the host loop, that just affects localhost (or groupname[0])

---

<div class="post-metadata">

**Author:** ![Imran\_Khan1](https://avatars.discourse-cdn.com/v4/letter/i/a4c791/32.png) [@Imran\_Khan1](https://forum.ansible.com/u/Imran_Khan1)\
**Post date:** [August 20, 2014, 10:23am UTC](https://forum.ansible.com/t/run-once-and-serial/15778/4 "2014-08-20T10:23:07Z")

</div>

I think the feature should be available because sometimes you need to run a task once, and then run the the playbook again, executing it by using some new result(s) ( such as content read from a file on a remote server)

---

<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:** [August 20, 2014, 12:00pm UTC](https://forum.ansible.com/t/run-once-and-serial/15778/5 "2014-08-20T12:00:38Z")

</div>

"I think the feature should be available because sometimes you need to run a task once, and then run the the playbook again, executing it by using some new result(s) ( such as content read from a file on a remote server) "

run\_once with serial now runs things once per serial batch.

If you need to run something _exactly_ once, you can put it in a seperate play above or below the play in the current playbook, and just target that host.
