How to reboot CentOS 7 with Ansible?

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

    At reboot time all ssh connections are closed. That's why the Ansible task fails. The ignore_errors: true or failed_when: false additions are no longer working as of Ansible 1.9.x because handling of ssh connections has changed and a closed connection now is a fatal error which can not be caught during play.

    The only way I figured out how to do it is to run a local shell task which then starts a separate ssh connection, which then may fail.

    - name: Rebooting
      delegate_to: localhost
      shell: ssh -S "none" {{ inventory_hostname }} sudo /usr/sbin/reboot"
      failed_when: false
      changed_when: true
    

提交回复
热议问题