ansible block not running as expected

268 views
Skip to first unread message

Adrian Paraschiv

unread,
Feb 15, 2017, 1:51:37 AM2/15/17
to Ansible Project

I have ansible 2.2.1.0 and I have this role:

- block:
    - shell: echo 1
    - shell: fail
    - shell: echo 2
  rescue:
    - shell: echo 3
  always:
    - shell: echo 4

- name: running something after the block
  shell: echo 5
 

If I run this role, the first part of the block fails because of the "fail" command (which does not exist :) "stderr: /bin/sh: 1: fail: not found") so the rescue kicks + always. But the last task, the one "running something after the block" never runs. The play finises!

Why is that ? The expected result I would see it as: if the first part of the block fails rescue kicks in + always (if any) and then continues the play run with the rest of the tasks.

In the documentation there is nothing about this.

Is there a workaround this ?

Kai Stian Olstad

unread,
Feb 15, 2017, 4:25:35 AM2/15/17
to ansible...@googlegroups.com
I can't confirm this with 2.2.1.0

---
- hosts: localhost
tasks:
- block:
- name: Task 1
shell: echo 1
- name: Task fail
shell: fail
- name: Task 2
shell: echo 2
rescue:
- name: Task 3
shell: echo 3
always:
- name: Task 4
shell: echo 4

- name: Task 5
shell: echo 5

$ ansible-playbook test.yml

PLAY [localhost]
***************************************************************

TASK [Task 1]
******************************************************************
changed: [localhost]

TASK [Task fail]
***************************************************************
fatal: [localhost]: FAILED! => {
"changed": true,
"cmd": "fail",
"delta": "0:00:00.001155",
"end": "2017-02-15 10:18:55.843553",
"failed": true,
"rc": 127,
"start": "2017-02-15 10:18:55.842398",
"warnings": []
}

STDERR:

/bin/sh: 1: fail: not found


TASK [Task 3]
******************************************************************
changed: [localhost]

TASK [Task 4]
******************************************************************
changed: [localhost]

TASK [Task 5]
******************************************************************
changed: [localhost]

PLAY RECAP
*********************************************************************
localhost : ok=5 changed=4 unreachable=0
failed=1


--
Kai Stian Olstad

Adrian Paraschiv

unread,
Feb 15, 2017, 4:28:00 AM2/15/17
to Ansible Project
Because I said it's a role and you put them as tasks ;)

Kai Stian Olstad

unread,
Feb 15, 2017, 5:00:42 AM2/15/17
to ansible...@googlegroups.com
On 15.02.2017 10:28, Adrian Paraschiv wrote:
> Because I said it's a role and you put them as tasks ;)

Sorry about that, I didn't think it would matter, but it does.
Testet the tasks in a role and it stopped as you say.

Testet Ansible 2.1.4.0 and 2.2.0.0 and there it works as expected, so
this bug/behaviour was introduced in 2.2.1.0.


--
Kai Stian Olstad

John Dhom

unread,
Feb 16, 2017, 1:36:24 AM2/16/17
to Ansible Project, ansible-pr...@olstad.com
That is correct. We ran into this last week as well. Found the bug here... https://github.com/ansible/ansible/issues/20736

Best,
/jhd

Kevin Carter

unread,
Jun 19, 2017, 11:35:29 AM6/19/17
to Ansible Project
++ Just we began running 2.2.3.0 and we're seeing this same behavior.
Reply all
Reply to author
Forward
0 new messages