# Method for checking the value of "serial"

**URL:** <https://forum.ansible.com/t/method-for-checking-the-value-of-serial/16815>\
**Category:** Ansible Project\
**Created:** [November 18, 2014, 7:31pm UTC](https://forum.ansible.com/t/method-for-checking-the-value-of-serial/16815 "2014-11-18T19:31:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucky\_numbersevun](https://avatars.discourse-cdn.com/v4/letter/l/c4cdca/32.png) [@lucky\_numbersevun](https://forum.ansible.com/u/lucky_numbersevun)\
**Post date:** [November 18, 2014, 7:31pm UTC](https://forum.ansible.com/t/method-for-checking-the-value-of-serial/16815/1 "2014-11-18T19:31:00Z")

</div>

Hello,

I have a playbook that updates the kernel version on ceph cluster members.  
Its important that we only do a single service at a time to prevent the OSD from trying to cope with a host when it reboots.

I want to verify that serial has been set to 1 and make sure that the playbook doesnt run otherwise.  
The following code doesnt work, is there a way to do this?

---

<div class="post-metadata">

**Author:** ![lucky\_numbersevun](https://avatars.discourse-cdn.com/v4/letter/l/c4cdca/32.png) [@lucky\_numbersevun](https://forum.ansible.com/u/lucky_numbersevun)\
**Post date:** [November 18, 2014, 7:45pm UTC](https://forum.ansible.com/t/method-for-checking-the-value-of-serial/16815/2 "2014-11-18T19:45:02Z")

</div>

My apologies, I quickly typed that question out…to clarify…

> I have a playbook that updates the kernel version on ceph cluster members.  
> Its important that we only do a single service at a time to prevent the OSD from trying to cope with a host when it reboots.

Its important that we only do a single SERVER at a time to prevent the cluster from incurring more than one down-server at a time.

🙂

Anyhow…just wanted to clear and concise about it…

-Lucky

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 18, 2014, 7:52pm UTC](https://forum.ansible.com/t/method-for-checking-the-value-of-serial/16815/3 "2014-11-18T19:52:31Z")

</div>

well, the only place you can set serial is on the play, that alone should ensure it.

but for the paranoid, you can use the play\_hosts variable to either check if it is a list lenght of 1 or that the only item inside it is inventory\_hostname.

---

<div class="post-metadata">

**Author:** ![Luca\_Menegus](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@Luca\_Menegus](https://forum.ansible.com/u/Luca_Menegus)\
**Post date:** [November 18, 2014, 8:46pm UTC](https://forum.ansible.com/t/method-for-checking-the-value-of-serial/16815/4 "2014-11-18T20:46:56Z")

</div>

I think you could leverage the play\_hosts var which contains the list of the hosts involved in the current play by asserting that its length is equal to 1 (a play start with hosts and tasks declaration, that is at the same level where you set the serial attr).

Bye,  
luca

PS: a little utility to dump ansible variables (Unfortunately I can’t remember where I copied it from so I can’t credit the author)

- template: src=debug\_all\_vars.j2 dest=/tmp/ansible.all.vars.debug

debug\_all\_vars.j2:

Module Variables (“vars”):

---

<div class="post-metadata">

**Author:** ![lucky\_numbersevun](https://avatars.discourse-cdn.com/v4/letter/l/c4cdca/32.png) [@lucky\_numbersevun](https://forum.ansible.com/u/lucky_numbersevun)\
**Post date:** [November 19, 2014, 10:56pm UTC](https://forum.ansible.com/t/method-for-checking-the-value-of-serial/16815/5 "2014-11-19T22:56:01Z")

</div>

This worked.

[..snip..]

tasks:

- debug: msg=“The system {{ inventory\_hostname }} will now be upgraded.”
- debug: msg=“The value of play\_hosts is {{ play\_hosts }}.”

# This ensures that we dont proceed unless we’re really only acting on a single host, for sure!

# Another option would be to refactor this playbook to accept a hostname/string as a target

# Another option would be to pass in --limit ‘somehost’ when running the playbook

- assert: { that: “play\_hosts | length == 1” }

# - debug: msg=“The variable play\_hosts is length of 1, which means that only a single host will be upgraded at a time, proceeding with upgrade to {{ inventory\_hostname }}”

[..snip..]

Thanks for the idea!

Lucky
