0

Is it possible to capture an exit code for an Ansible role or playbook (not each individual task) and branch depending on the exit code?

We have an application that needs to create a specific flag (success/failure) for each Ansible ROLE, not task. One exit code per role.

  • Could you give a concrete example, since there should be a way to solve this without any exit codes. Also exit codes don't exist for roles, only processes have exit codes. – Strahinja Kustudic Apr 19 '16 at 22:35

1 Answers1

0

You can catch the error of the include module. I mean if you create a role and inside the tasks there is a main.yml which looks like this:

---
- include: first_server.yml
  register: first_server

- include: second_server.yml
  register: second_server
  when: first_server | success

In the next role which will be the web:

---
- include: first_web.yml
  register: first_web
  when: second_server | success

- include: second_web.yml
  register: second_web
  when: second_server | success
PumpkinSeed
  • 2,945
  • 9
  • 36
  • 62