how to abort execution upon a single fail on any host

50 views
Skip to first unread message

Leon Xie

unread,
Jul 29, 2015, 8:49:38 AM7/29/15
to Ansible Project
hi all,

I have the below playbooks:


+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- hosts: aa
  max_fail_percentage: 0
  roles:
    - stop_server

- hosts: allhosts
  max_fail_percentage: 0
  roles:
    - backup_data

- hosts: localhost
  max_fail_percentage: 0
  roles:
    - prepare_data

+++++++++++++++++++++++++++++++++++++++++++++++++++++++
what I get now is that even if any task in stop_server role fail, the task in backup_data for allhosts still runs.

what I want is that if any failure occurs in any host, the other tasks won't be run for the remaining hosts.
is there a way to achieve this?


Serge van Ginderachter

unread,
Jul 29, 2015, 8:54:59 AM7/29/15
to ansible...@googlegroups.com

On 29 July 2015 at 14:49, Leon Xie <qdxia...@gmail.com> wrote:
max_fail_percentage:


​Perhaps ​any_errors_fatal: true might help?

(btw Seems undocumented)

Leon Xie

unread,
Jul 29, 2015, 9:15:15 AM7/29/15
to Ansible Project, se...@vanginderachter.be
thanks a lot for your suggestion.
I had a try by adding any_errors_fatal: true.
however, it doesn't work.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- hosts: aa
  max_fail_percentage: 0
  any_errors_fatal: true
  roles:
    - stop_server

- hosts: allhosts
  max_fail_percentage: 0
  roles:
    - backup_data
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++
PLAY [aa] ********************************************************************

TASK: [stop_server | stop server] ***************************************
failed: [xxx.xxx.0.xx] => {"attempts": 1, "changed": true, "cmd": ["xxxxxxx"], "delta": "0:00:00.006697", "end": "2015-07-29 21:04:35.801786", "failed": true, "rc": 255, "start": "2015-07-29 21:04:35.795089", "warnings": []}
msg: Task failed as maximum retries was encountered

PLAY [allhosts] ******************************************************************

TASK: [backup_data | create directory] ***************************
ok: [xx.xxx.0.xx]
ok: [xx.xxx.0.xx]

TASK: [backup_data | mount directory] *************************************
skipping: [xx.xxx.0.xx]
skipping: [xx.xxx.0.xx]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Leon Xie

unread,
Jul 29, 2015, 9:39:21 AM7/29/15
to Ansible Project, qdxia...@gmail.com
my ansible version is as below:

$ ansible-playbook --version
ansible-playbook 1.9.1
  configured module search path = None

Leon Xie

unread,
Jul 29, 2015, 10:24:34 AM7/29/15
to Ansible Project, se...@vanginderachter.be
Hi Serge,

your suggestion about any_errors_fatal works for the hosts that in a single play.
if there is another play and one of the hosts in the play is not in the hosts that marked as any_errors_fatal, the tasks in this play will also be executed.



On Wednesday, July 29, 2015 at 8:54:59 PM UTC+8, Serge van Ginderachter wrote:
Reply all
Reply to author
Forward
0 new messages