Block/Rescue/Always Exit Code

297 views
Skip to first unread message
Message has been deleted

João Cravo

unread,
Jul 13, 2017, 1:59:59 PM7/13/17
to Ansible Project

Hi!

When I use Block that has a task that fails, and then I rescue it, what should be the ansible exit code? AFAIK, on the documentation, there is no information about it. 


I have a scenario where I would like to use rescue with the "rollback" tasks, and then would like Ansible to return an exit code != 0, but with the "rescue block", I got always 0.


Example playbook:

- hosts: localhost
  gather_facts: False

  tasks:
    - block:
        - fail: msg="fail"
      rescue:
        - debug: msg="rescue"
      always:
        - debug: msg="always"

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


When we run this simple playbook and then do "echo $?" I got 0 instead of != 0 
If there are failed tasks (and they aren't ignored) I would expect a failed playbook... 

Am I thinking right? What is your opinion?

PS: I open an issue giving some ideas for feature flag on the block: https://github.com/ansible/ansible/issues/26595


Brian Coca

unread,
Jul 13, 2017, 4:32:25 PM7/13/17
to Ansible Project
Since the task is rescued, the play does not fail, so the ansible
return code is 0 (unless something else happens).


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages