I'd do it by putting the head node into a group of it's own, to make it
more explicit
- hosts: cluster
tasks:
- ...
- hosts: cluster:!head_node
tasks:
- ...
- hosts: head_node
tasks:
- ...
Just personal preference but where I can avoid if conditionals, I try to.
Ansible likes to avoid programming constructs when it can.
On Fri, May 2, 2014 at 11:33 AM, James Cammarata <[email protected]>wrote:
> To handle this, I would create a custom fact (
> http://docs.ansible.com/playbooks_variables.html#local-facts-facts-d)
> that returned whether the current host is in the master state. Then you
> could write two tasks as follows:
>
> - name: shut down non-masters
> # <- whatever method you're using to shut things down, ie. service, etc.
> when: not ansible_local.master_status.is_master
>
> - name: shut down the master last
> # <- whatever method you're using to shut things down, ie. service, etc.
> when: ansible_local.master_status.is_master
>
> Assuming the local fact was named "master_status.fact" and it returned
> JSON like {'is_master': true}.
>
>
>
> On Fri, May 2, 2014 at 10:05 AM, nfwlpw <[email protected]> wrote:
>
>> This might be a newbie question, but I can't figure out how to without
>> writing a wrapper around ansible, or invoking ansible multiple times
>>
>> Let's say this is my inventory:
>>
>> [some_service]
>> A
>> B
>> C
>>
>> Some_service runs in synchronization mode so one is the master, which
>> need to be shut down last.
>>
>> The trouble is I do not know without actually running "some_command"
>> which one is the master, so the shutdown order might be B->C->A or A->C->B,
>> etc.
>>
>> Is it possible to have ansible runs normally over these hosts, read the
>> exit status of "some_command" and then delay executing shutdown on master
>> until the others are done?
>>
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/41bb1f9a-060a-4d1e-a2ae-0a0eabd124d6%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/41bb1f9a-060a-4d1e-a2ae-0a0eabd124d6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAMFyvFi9pWxACXcqaoDt13seHfRktiQa3Q9%3D%2Bomj6Sxjsp%3D-tA%40mail.gmail.com<https://groups.google.com/d/msgid/ansible-project/CAMFyvFi9pWxACXcqaoDt13seHfRktiQa3Q9%3D%2Bomj6Sxjsp%3D-tA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwJCV4zZXFsQFQwn82Q2KVO5fXjFjgLCNXuaG_mijRh5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.