How to wait for server restart using Ansible?

后端 未结 11 1184
半阙折子戏
半阙折子戏 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

    In case you don't have DNS setup for the remote server yet, you can pass the IP address instead of a variable hostname:

    - name: Restart server
      command: shutdown -r now
    
    - name: Wait for server to restart successfully
      local_action:
        module: wait_for
          host={{ ansible_default_ipv4.address }}
          port=22
          delay=1
          timeout=120
    

    These are the two tasks I added to the end of my ansible-swap playbook (to install 4GB of swap on new Digital Ocean droplets.

提交回复
热议问题