How to reboot CentOS 7 with Ansible?

前端 未结 11 1615
遥遥无期
遥遥无期 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 07:56

    Another solution:

    - name: reboot host
      command: /usr/bin/systemd-run --on-active=10 /usr/bin/systemctl reboot
      async: 0
      poll: 0
    
    - name: wait for host sshd
      local_action: wait_for host="{{ inventory_hostname }}" search_regex=OpenSSH port=22 timeout=300 delay=30
    

    systemd-run creates "on the fly" new service which will start systemctl reboot after 10 sec of delay (--on-active=10). delay=30 in wait_for to add extra 20 sec to be sure that host actually started rebooting.

提交回复
热议问题