How to retry Ansible task that may fail?

前端 未结 4 2126
[愿得一人]
[愿得一人] 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:04

    Consider using wait_for module. It waits for a condition before continuing, for example for a port to become open or closed, for a file to exist or not, or for some content in a file.

    Without seeing the rest of your playbook, consider the following example:

    - name: Wait for db server to restart
      local_action:
        wait_for:
          host=192.168.50.4
          port=3306
          delay=1
          timeout=300
    

    You can also adapt it as a handler and obviously change this snippet to suit your use-case.

提交回复
热议问题