How to reboot CentOS 7 with Ansible?

前端 未结 11 1543
遥遥无期
遥遥无期 2020-12-24 07:46

I\'m trying to reboot server running CentOS 7 on VirtualBox. I use this task:

- name: Restart server
  command: /sbin/reboot
  async: 0
  poll:          


        
11条回答
  •  时光取名叫无心
    2020-12-24 08:03

    I am using Ansible 2.5.3. Below code works with ease,

    - name: Rebooting host
      shell: 'shutdown -r +1 "Reboot triggered by Ansible"'
    
    - wait_for_connection:
        delay: 90
        timeout: 300
    

    You can reboot immediately, then insert a delay if your machine takes a while to go down:

        - name: Rebooting host
          shell: 'shutdown -r now "Reboot triggered by Ansible"'
          async: 1
          poll: 1
          ignore_errors: true
    
    # Wait 120 seconds to make sure the machine won't connect immediately in the next section.
        - name: Delay for the host to go down
          local_action: shell /bin/sleep 120
    

    Then poll to make the playbook return as soon as possible:

        - name: Wait for the server to finish rebooting
          wait_for_connection:
            delay: 15
            sleep: 15
            timeout: 300
    

    This will make the playbook return as soon as possible after the reboot.

提交回复
热议问题