validate_restart.yml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ---
  2. - name: Validate configuration for rolling restart
  3. hosts: oo_masters_to_config
  4. roles:
  5. - openshift_facts
  6. tasks:
  7. - fail:
  8. msg: "openshift_rolling_restart_mode must be set to either 'services' or 'system'"
  9. when: openshift_rolling_restart_mode is defined and openshift_rolling_restart_mode not in ["services", "system"]
  10. # Creating a temp file on localhost, we then check each system that will
  11. # be rebooted to see if that file exists, if so we know we're running
  12. # ansible on a machine that needs a reboot, and we need to error out.
  13. - name: Create temp file on localhost
  14. hosts: localhost
  15. connection: local
  16. gather_facts: no
  17. tasks:
  18. - local_action: command mktemp
  19. register: mktemp
  20. changed_when: false
  21. - name: Check if temp file exists on any masters
  22. hosts: oo_masters_to_config
  23. tasks:
  24. - stat: path="{{ hostvars.localhost.mktemp.stdout }}"
  25. register: exists
  26. changed_when: false
  27. when: "'stdout' in hostvars.localhost.mktemp"
  28. - name: Cleanup temp file on localhost
  29. hosts: localhost
  30. connection: local
  31. gather_facts: no
  32. tasks:
  33. - file: path="{{ hostvars.localhost.mktemp.stdout }}" state=absent
  34. changed_when: false
  35. when: "'stdout' in hostvars.localhost.mktemp"
  36. - name: Warn if restarting the system where ansible is running
  37. hosts: oo_masters_to_config
  38. tasks:
  39. - pause:
  40. prompt: >
  41. Warning: Running playbook from a host that will be restarted!
  42. Press CTRL+C and A to abort playbook execution. You may
  43. continue by pressing ENTER but the playbook will stop
  44. executing after this system has been restarted and services
  45. must be verified manually. To only restart services, set
  46. openshift_master_rolling_restart_mode=services in host
  47. inventory and relaunch the playbook.
  48. when:
  49. - "'stat' in exists"
  50. - exists.stat.exists and openshift_rolling_restart_mode | default('services') == 'system'
  51. - set_fact:
  52. current_host: "{{ exists.stat.exists }}"
  53. when:
  54. - "'stat' in exists"
  55. - openshift_rolling_restart_mode | default('services') == 'system'