I have a playbook tat contains (Among other) three specfic tasks.
- name: Execute the compilation script
command: sh {{ working_folder }}/compile.sh
args:
chdir: "{{ working_folder }}"
when: run_deploy_machine == "true"
- name: Execute the deployment script
command: sh {{ working_folder }}/deploy.sh
args:
chdir: "{{ working_folder }}"
when: run_deploy_machine == "true"
- name: Start the JBoss server
shell: . /jboss start
THe problem is that if any of the first two tasks fails, I need (As part of the failure process) activate the logic of the last task (It might be as a handler). I saw that there is the block/rescue option, the problem is that if I use it- the rescue "cancel" the failure. All I need is that in case of the failure- to execute the start JBoss, but that the playbook will still fail.
Any ideas how it can be done?
You can still use a block/rescue and use a fail task at the end of the rescue tasks. Here is a global idea:
---
- name: Clean fail in rescue demo
hosts: localhost
gather_facts: false
tasks:
- block:
- name: task that may fail
command: /bin/false
- name: other task that might fail
command: /does/this/work
rescue:
- name: task to remedy fail
command: echo remedy
- name: cleanly fail the host anyway
fail:
msg: clean fail after remedy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With