Method for checking the value of "serial"

63 views
Skip to first unread message

lucky numbersevun

unread,
Nov 18, 2014, 2:31:00 PM11/18/14
to ansible...@googlegroups.com
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?


++++

   - fail: msg="This playbook needs to be run with serial:1 so that only a single host is upgraded at a time"
     when: serial != "1"

++++

Thanks for your feedback/consideration/ideas/corrections-in-thinking/etc

best,

Lucky

lucky numbersevun

unread,
Nov 18, 2014, 2:45:02 PM11/18/14
to ansible...@googlegroups.com
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

Brian Coca

unread,
Nov 18, 2014, 2:52:36 PM11/18/14
to ansible...@googlegroups.com
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.


--
Brian Coca

Luca Menegus

unread,
Nov 18, 2014, 3:50:09 PM11/18/14
to ansible...@googlegroups.com

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

--------------------------------
{{ vars | to_nice_json }}

Environment Variables ("environment"):
--------------------------------
{{ environment | to_nice_json }}

GROUP NAMES Variables ("group_names"):
--------------------------------
{{ group_names | to_nice_json }}

GROUPS Variables ("groups"):
--------------------------------
{{ groups | to_nice_json }}



Luca

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8nfMyAV32LSbT%3DPO3u87iyPNAykfmejp7MsOreVUVysyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

lucky numbersevun

unread,
Nov 19, 2014, 5:56:01 PM11/19/14
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages