Hi.
I'm working on some orchestration where I need to run a task across sets of
N remote nodes. If that task fails on any one of the remote nodes, the
orchestration needs to halt (or be handled somehow). In my test, I cause
one node to fail and I expected the entire ansible run to bomb out, but
that's not what happened. The failed node is reported, but the playbook
continues on.
How can I make ansible exit upon the failure of any one of these nodes?
Or, how can I have some kind of handler to pause the run before continuing?
(I've not yet looked into handlers)
Playbook, plays, tasks, and output are shown below. One question about the
output: for the node that failed, the task "debug: var=output" is absent.
That task only fires for the successful node. Should I expect that task to
also fire for the failed node? I was surprised by that.
Thanks!
kallen
$ cat testplaybook.yml
---
- hosts: 127.0.0.1
connection: local
gather_facts: False
tasks:
- include: "{{ playbook_dir }}/common/test.yml myhosts=app_set1"
- include: "{{ playbook_dir }}/common/test2.yml"
$ cat common/test.yml
---
- hosts: '{{ myhosts }}'
gather_facts: false
tasks:
- debug: msg="working on {{ play_hosts }}."
- name: Simple script exits 1 or 0
shell: /usr/local/bin/check
sudo: yes
register: output
- debug: var=output
- debug: msg="FAILED - script exited non-zero"
failed_when: output['rc'] != 0
$ cat common/test2.yml
---
- hosts: 127.0.0.1
connection: local
gather_facts: false
tasks:
- debug: msg="If any hosts failed prior to this, you shouldn't see this
message."
$ ansible-playbook -i inventory/inv.ini testplaybook.yml
PLAY [127.0.0.1]
**************************************************************
Thursday 06 August 2015 18:51:10 +0000 (0:00:00.018) 0:00:00.018
*******
===============================================================================
PLAY [app_set1] ***********************************************
Thursday 06 August 2015 18:51:10 +0000 (0:00:00.000) 0:00:00.018
*******
===============================================================================
TASK: [debug msg="working on {{ play_hosts }}."]
******************************
Thursday 06 August 2015 18:51:10 +0000 (0:00:00.004) 0:00:00.022
*******
ok: [webapp01b.aue1t.example.com] => {
"msg": "working on ['webapp01b.aue1t.example.com',
'webapp01e.aue1t.example.com']."
}
ok: [webapp01e.aue1t.example.com] => {
"msg": "working on ['webapp01b.aue1t.example.com',
'webapp01e.aue1t.example.com']."
}
TASK: [Simple script exits 1 or 0]
********************************************
Thursday 06 August 2015 18:51:10 +0000 (0:00:00.087) 0:00:00.110
*******
failed: [webapp01b.aue1t.example.com] => {"changed": true, "cmd":
"/usr/local/bin/check", "delta": "0:00:00.014861", "end": "2015-08-06
18:51:11.585755", "rc": 1, "start": "2015-08-06 18:51
:11.570894", "warnings": []}
stdout: exiting 1
changed: [webapp01e.aue1t.example.com]
TASK: [debug var=output]
******************************************************
Thursday 06 August 2015 18:51:11 +0000 (0:00:01.466) 0:00:01.576
*******
ok: [webapp01e.aue1t.example.com] => {
"output": {
"changed": true,
"cmd": "/usr/local/bin/check",
"delta": "0:00:00.009886",
"end": "2015-08-06 18:51:11.654924",
"invocation": {
"module_args": "/usr/local/bin/check",
"module_name": "shell"
},
"rc": 0,
"start": "2015-08-06 18:51:11.645038",
"stderr": "",
"stdout": "exiting 0",
"stdout_lines": [
"exiting 0"
],
"warnings": []
}
}
TASK: [debug msg="FAILED - script exited non-zero"]
***************************
Thursday 06 August 2015 18:51:11 +0000 (0:00:00.023) 0:00:01.600
*******
ok: [webapp01e.aue1t.example.com] => {
"failed": false,
"failed_when_result": false,
"msg": "FAILED - script exited non-zero"
}
PLAY [127.0.0.1]
**************************************************************
Thursday 06 August 2015 18:51:11 +0000 (0:00:00.019) 0:00:01.619
*******
===============================================================================
TASK: [debug msg="If any hosts failed prior to this, you shouldn't see this
message."] ***
Thursday 06 August 2015 18:51:11 +0000 (0:00:00.000) 0:00:01.620
*******
ok: [127.0.0.1] => {
"msg": "If any hosts failed prior to this, you shouldn't see this
message."
}
PLAY RECAP
********************************************************************
Thursday 06 August 2015 18:51:11 +0000 (0:00:00.002) 0:00:01.622
*******
===============================================================================
to retry, use: --limit @/home/kallen/testplaybook.retry
127.0.0.1 : ok=1 changed=0 unreachable=0 failed=0
webapp01b.aue1t.example.com : ok=1 changed=0 unreachable=0 failed=1
webapp01e.aue1t.example.com : ok=4 changed=1 unreachable=0 failed=0
--
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/a21f5cb9-3a9b-429e-9831-ca583f1481d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.