How to wait for server restart using Ansible?

后端 未结 11 1180
半阙折子戏
半阙折子戏 2020-12-07 13:06

I\'m trying to restart the server and then wait, using this:

- name: Restart server
  shell: reboot

- name: Wait for server to restart
  wait_for:
    port=         


        
11条回答
  •  抹茶落季
    2020-12-07 13:29

    2018 Update

    As of 2.3, Ansible now ships with the wait_for_connection module, which can be used for exactly this purpose.

    #
    ## Reboot
    #
    
    - name: (reboot) Reboot triggered
      command: /sbin/shutdown -r +1 "Ansible-triggered Reboot"
      async: 0
      poll: 0
    
    - name: (reboot) Wait for server to restart
      wait_for_connection:
        delay: 75
    

    The shutdown -r +1 prevents a return code of 1 to be returned and have ansible fail the task. The shutdown is run as an async task, so we have to delay the wait_for_connection task at least 60 seconds. 75 gives us a buffer for those snowflake cases.

    wait_for_connection - Waits until remote system is reachable/usable

提交回复
热议问题