How to reboot CentOS 7 with Ansible?

前端 未结 11 1613
遥遥无期
遥遥无期 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

    Yet another (combined from other answers) version:

    ---
    - name: restart server
      command: /usr/bin/systemd-run --on-active=5 --timer-property=AccuracySec=100ms /usr/bin/systemctl reboot
      async: 0
      poll: 0
      ignore_errors: true
      become: yes
    
    - name: wait for server {{ ansible_ssh_host | default(inventory_hostname) }} to come back online
      wait_for:
        port: 22
        state: started
        host: '{{ ansible_ssh_host | default(inventory_hostname) }}'
        delay: 30
      delegate_to: localhost
    

提交回复
热议问题