简体   繁体   中英

Ansible exit code for a role or a playbook, not each individual task

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM