Method for checking the value of "serial"

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?

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.

:slight_smile:

Anyhow…just wanted to clear and concise about it…

-Lucky

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.

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”):

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