You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.1 KiB

  1. ---
  2. # Reboot the machine gets more complicated as we want to support bastion hosts. A simple wait_for task would not work
  3. # as we can not directly reach the hosts (except the bastion). In case a basion is used, we first check for it to come
  4. # back. After it is back, we check for all the hosts by delegating to the bastion.
  5. - name: Rebooting server
  6. shell: nohup bash -c "sleep 5 && shutdown -r now 'Reboot required for updated kernel'" &
  7. - name: Wait for some seconds
  8. pause: seconds=10
  9. - set_fact:
  10. is_bastion: "{{ inventory_hostname == 'bastion' }}"
  11. wait_for_delegate: "localhost"
  12. - set_fact:
  13. wait_for_delegate: "{{hostvars['bastion']['ansible_ssh_host']}}"
  14. when: "{{ 'bastion' in groups['all'] }}"
  15. - name: wait for bastion to come back
  16. wait_for: host={{ ansible_ssh_host }} port=22 delay=10 timeout=300
  17. become: false
  18. delegate_to: localhost
  19. when: "is_bastion"
  20. - name: waiting for server to come back (using bastion if necessary)
  21. wait_for: host={{ ansible_ssh_host }} port=22 delay=10 timeout=300
  22. become: false
  23. delegate_to: "{{ wait_for_delegate }}"
  24. when: "not is_bastion"