3

I have created a role named cleanup which is my final role in playbook (which handles some cleanups after running all otherroles)

here is a simplified version of my playbook

- hosts: myhost
  roles:
    - common
    - postgresql
    - rabbitmq
    - web
    - cleanup

the problem is if playbook fails ansible doesn't run clean role, how can I mark that specific role as important, so ansible would run it even all other roles in playbook has failed?

2

Ansible has ignore_errors feature for tasks. But your case about whole role. I think you can seperate roles two chapters in a playbook file. Thats tricky but efficient.

- hosts: myhost
  roles:
    - common
    - rabbitmq

- hosts: myhost
  roles:
    - cleanup

So if you raise any fail on first chapter playbook will keep continue on next chapter :)

Also ! Ansible 2.0 has new block mechanism, thats not what exactly you want but maybe you think re-design your logic mechanism.

tasks:
 block:
  - debug: msg='i execute normally'
  - command: /bin/false
  - debug: msg='i never execute, cause ERROR'
 rescue:
  - debug: msg='I caught an error'
  - command: /bin/false
  - debug: msg='I also never execute :-('
 always:
  - debug: msg="this always executes"

Ansible Blocks

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.