Try-Catch in ansible with timeout on task

2019-08-24 14:54发布

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?

标签: ansible
1条回答
淡お忘
2楼-- · 2019-08-24 15:31

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"
查看更多
登录 后发表回答