Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try-Catch in ansible with timeout on task

Tags:

ansible

Let's consider following pseudo-ansible code:

- name: "some long task which can hang
- command: "something"  
- timeout: 60s

- name: "catch in case of failure (in particularity timeout)"
- command: "some helpful debug command"

Is it possible to do in ansible?

like image 306
Docker fun Avatar asked Oct 30 '25 21:10

Docker fun


1 Answers

Read the docs on Ansible Blocks They allow you to amongst other things do stuff like:

- block:
    - debug:
        msg: "This is a basic task that will run in the block"
  rescue:
    - debug:
        msg: "This task will only run if something fails in the main block
  always:
    - debug:
        msg: "This task always runs, irrespective of whether the tasks in the main block succeed or not"
like image 181
clockworknet Avatar answered Nov 03 '25 08:11

clockworknet