How to reboot CentOS 7 with Ansible?

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

    You're likely not doing anything truly wrong, it's just that /sbin/reboot is shutting down the server so quickly that the server is tearing down the SSH connection used by Ansible before Ansible itself can close it. As a result Ansible is reporting an error because it sees the SSH connection failing for an unexpected reason.

    What you might want to do to get around this is to switch from using /sbin/reboot to using /sbin/shutdown instead. The shutdown command lets you pass a time, and when combined with the -r switch it will perform a reboot rather than actually shutting down. So you might want to try a task like this:

    - name: Restart server
      command: /sbin/shutdown -r +1
      async: 0
      poll: 0
      ignore_errors: true
    

    This will delay the server reboot for 1 minute, but in doing so it should give Ansible enough time to to close the SSH connection itself, thereby avoiding the error that you're currently getting.

提交回复
热议问题