Open kustodian opened 6 years ago
They are supposed to handle task 'failed' state, in an interruption, the task won't get a state assigned. That said, I would not be against this feature as long as it had a toggle for it.
I support this. One Ctrl+C to start a clean cancel (which runs always/rescue), and if they run Ctrl+C again during the clean cancel, it forcefully exits. A PLAY RECAP at the end showing all the hosts (that have not finished yet) "failed" would be nice to complement this.
Proposal: Run
always
/rescue
tasks when cancelling a task in ablock
withSIGINT
/SIGTERM
Author: Strahinja Kustudic @kustodian
Date: 2018/06/15
Motivation
Ansible has blocks and they allow us to have tasks which will be executed in case of failure which should be stated in the
rescue
section and tasks which should be run all the time which is stated in thealways
sections. This is very useful if you need to do some clean up, or some post tasks in case of failure, or always.Problems
The problem is that if you cancel a task in a block which has a
rescue
/always
sections by sendingSIGINT
/SIGTERM
to theansible-playbook
process, Ansible just stops the execution and exits, it doesn't run the tasks inrescue
/always
sections.For example we have the following playbook which runs some stress tests which looks like this:
So what I expect from this playbook when press
CTRL+C
is that it executes thealways
tasks so my hosts are clean from the sysbench package and files create by it.Solution proposal
Make
ansible-playbook
treatSIGHUP
/SIGTERM
signals special and when cancelling a task with one of those signals execute thealways
/rescue
sections, then stop the execution, so that possible clean up tasks can execute regularly.One other important reason why
always
/rescue
should execute is because if I want them to execute when the tasks fail, why I wouldn't want to execute them in case I cancelled the task? Also if for some reason we want to cancel tasks in those sections, you can always press CTRL+C again.