How to retry Ansible task that may fail?

前端 未结 4 1800
[愿得一人]
[愿得一人] 2020-12-29 18:26

In my Ansible play I am restarting database then trying to do some operations on it. Restart command returns as soon as restart is started, not when db is up. Next command t

4条回答
  •  伪装坚强ぢ
    2020-12-29 19:01

    I don't understand your claim that the "first command execution fails whole play". It wouldn't make sense if Ansible behaved this way.

    The following task:

    - command: /usr/bin/false
      retries: 3
      delay: 3
      register: result
      until: result.rc == 0
    

    produces:

    TASK [command] ******************************************************************************************
    FAILED - RETRYING: command (3 retries left).
    FAILED - RETRYING: command (2 retries left).
    FAILED - RETRYING: command (1 retries left).
    fatal: [localhost]: FAILED! => {"attempts": 3, "changed": true, "cmd": ["/usr/bin/false"], "delta": "0:00:00.003883", "end": "2017-05-23 21:39:51.669623", "failed": true, "rc": 1, "start": "2017-05-23 21:39:51.665740", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
    

    which seems to be exactly what you want.

提交回复
热议问题