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.

40 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:
  9. seconds: 10
  10. - set_fact:
  11. is_bastion: "{{ inventory_hostname == 'bastion' }}"
  12. wait_for_delegate: "localhost"
  13. - set_fact:
  14. wait_for_delegate: "{{hostvars['bastion']['ansible_ssh_host']}}"
  15. when: "{{ 'bastion' in groups['all'] }}"
  16. - name: wait for bastion to come back
  17. wait_for:
  18. host: "{{ ansible_ssh_host }}"
  19. port: 22
  20. delay: 10
  21. timeout: 300
  22. become: false
  23. delegate_to: localhost
  24. when: "is_bastion"
  25. - name: waiting for server to come back (using bastion if necessary)
  26. wait_for:
  27. host: "{{ ansible_ssh_host }}"
  28. port: 22
  29. delay: 10
  30. timeout: 300
  31. become: false
  32. delegate_to: "{{ wait_for_delegate }}"
  33. when: "not is_bastion"