stop task on all hosts when task is finished in any of them

25 views
Skip to first unread message

Ivo Jimenez

unread,
Nov 13, 2017, 5:49:01 PM11/13/17
to Ansible Project
I've been trying to find a way of accomplishing this (what the subject says). I thought on using blocks, for example:


- block:
 
- name: run task
    command
: <my-command>
   
register: command_result
    failed_when
: command_result.changed
 
rescue:
 
- name: stop task on all other nodes
    command
: <stop-command>
    delegate_to
: '{{ item }}'
    with_items
: '{{ groups.all }}'

Can you think of any other alternative?

Thanks!

Ivo Jimenez

unread,
Nov 13, 2017, 7:06:52 PM11/13/17
to Ansible Project
Forgot to mention that the reason what the above doesn't work is because the `rescue` tasks are executed only after _all_ the hosts have finished executing the task

Kai Stian Olstad

unread,
Nov 14, 2017, 9:41:34 AM11/14/17
to ansible...@googlegroups.com
On Tuesday, 14 November 2017 01.06.51 CET Ivo Jimenez wrote:
> Forgot to mention that the reason what the above doesn't work is because
> the `rescue` tasks are executed only after _all_ the hosts have finished
> executing the task

Maybe strategy: free will help.
https://docs.ansible.com/ansible/latest/playbooks_strategies.html#strategies


--
Kai Stian Olstad

Ivo Jimenez

unread,
Nov 14, 2017, 1:14:08 PM11/14/17
to Ansible Project
Thanks for the suggestion. The problem is that I have other tasks (like local_action) that are not compatible with 'strategy: free'

Kai Stian Olstad

unread,
Nov 14, 2017, 2:33:07 PM11/14/17
to ansible...@googlegroups.com
On Tuesday, 14 November 2017 19.14.08 CET Ivo Jimenez wrote:
> Thanks for the suggestion. The problem is that I have other tasks (like
> local_action) that are not compatible with 'strategy: free'

To my knowledge strategy free and local_action is not a problem, do mean that you task is not compatible?

If so you are pretty much out of luck since strategy linear work by running all task on all host before advancing to the next.
One thing could be to split the play in three.
One play with linear, one with free that only run that particular task, and then the last play with linear again.

--
Kai Stian Olstad

Ivo Jimenez

unread,
Nov 14, 2017, 4:26:35 PM11/14/17
to ansible...@googlegroups.com
Sorry, I meant ‘run_once’ (it’s incompatible because every host is going on independently). I think I’ll go with having multiple playbooks. Thanks!

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/hhDZ_HSGRkA/unsubscribe.
To unsubscribe from this group and all its topics, 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/2893024.39OibzTt0K%40x1.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages