Try-Catch in ansible with timeout on task

2019-08-24 15:04发布

问题:

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?

回答1:

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"


标签: ansible