restart.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ---
  2. - include: ../openshift-cluster/evaluate_groups.yml
  3. - name: Validate configuration for rolling restart
  4. hosts: oo_masters_to_config
  5. roles:
  6. - openshift_facts
  7. tasks:
  8. - fail:
  9. msg: "openshift_rolling_restart_mode must be set to either 'services' or 'system'"
  10. when: openshift_rolling_restart_mode is defined and openshift_rolling_restart_mode not in ["services", "system"]
  11. - openshift_facts:
  12. role: "{{ item.role }}"
  13. local_facts: "{{ item.local_facts }}"
  14. with_items:
  15. - role: common
  16. local_facts:
  17. rolling_restart_mode: "{{ openshift_rolling_restart_mode | default('services') }}"
  18. - role: master
  19. local_facts:
  20. cluster_method: "{{ openshift_master_cluster_method | default(None) }}"
  21. # Creating a temp file on localhost, we then check each system that will
  22. # be rebooted to see if that file exists, if so we know we're running
  23. # ansible on a machine that needs a reboot, and we need to error out.
  24. - name: Create temp file on localhost
  25. hosts: localhost
  26. connection: local
  27. become: no
  28. gather_facts: no
  29. tasks:
  30. - local_action: command mktemp
  31. register: mktemp
  32. changed_when: false
  33. - name: Check if temp file exists on any masters
  34. hosts: oo_masters_to_config
  35. tasks:
  36. - stat: path="{{ hostvars.localhost.mktemp.stdout }}"
  37. register: exists
  38. changed_when: false
  39. - name: Cleanup temp file on localhost
  40. hosts: localhost
  41. connection: local
  42. become: no
  43. gather_facts: no
  44. tasks:
  45. - file: path="{{ hostvars.localhost.mktemp.stdout }}" state=absent
  46. changed_when: false
  47. - name: Warn if restarting the system where ansible is running
  48. hosts: oo_masters_to_config
  49. tasks:
  50. - pause:
  51. prompt: >
  52. Warning: Running playbook from a host that will be restarted!
  53. Press CTRL+C and A to abort playbook execution. You may
  54. continue by pressing ENTER but the playbook will stop
  55. executing once this system restarts and services must be
  56. manually verified.
  57. when: exists.stat.exists and openshift.common.rolling_restart_mode == 'system'
  58. - set_fact:
  59. current_host: "{{ exists.stat.exists }}"
  60. when: openshift.common.rolling_restart_mode == 'system'
  61. - name: Determine which masters are currently active
  62. hosts: oo_masters_to_config
  63. tasks:
  64. - name: Check master service status
  65. command: >
  66. systemctl is-active {{ openshift.common.service_type }}-master
  67. register: active_check_output
  68. when: openshift.master.cluster_method == 'pacemaker'
  69. failed_when: active_check_output.stdout not in ['active', 'inactive']
  70. changed_when: false
  71. - set_fact:
  72. is_active: "{{ active_check_output.stdout == 'active' }}"
  73. when: openshift.master.cluster_method == 'pacemaker'
  74. - name: Evaluate master groups
  75. hosts: localhost
  76. become: no
  77. tasks:
  78. - name: Evaluate oo_active_masters
  79. add_host:
  80. name: "{{ item }}"
  81. groups: oo_active_masters
  82. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  83. ansible_sudo: "{{ g_sudo | default(omit) }}"
  84. with_items: "{{ groups.oo_masters_to_config | default([]) }}"
  85. when: (hostvars[item]['is_active'] | default(false)) | bool
  86. - name: Evaluate oo_current_masters
  87. add_host:
  88. name: "{{ item }}"
  89. groups: oo_current_masters
  90. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  91. ansible_sudo: "{{ g_sudo | default(omit) }}"
  92. with_items: "{{ groups.oo_masters_to_config | default([]) }}"
  93. when: (hostvars[item]['current_host'] | default(false)) | bool
  94. - name: Validate pacemaker cluster
  95. hosts: oo_active_masters
  96. tasks:
  97. - name: Retrieve pcs status
  98. command: pcs status
  99. register: pcs_status_output
  100. changed_when: false
  101. - fail:
  102. msg: >
  103. Pacemaker cluster validation failed. One or more nodes are not online.
  104. when: not (pcs_status_output.stdout | validate_pcs_cluster(groups.oo_masters_to_config)) | bool
  105. - name: Restart masters
  106. hosts: oo_masters_to_config:!oo_active_masters:!oo_current_masters
  107. vars:
  108. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  109. serial: 1
  110. tasks:
  111. - include: restart_hosts.yml
  112. when: openshift.common.rolling_restart_mode == 'system'
  113. - include: restart_services.yml
  114. when: openshift.common.rolling_restart_mode == 'services'
  115. - name: Restart active masters
  116. hosts: oo_active_masters
  117. serial: 1
  118. tasks:
  119. - include: restart_hosts_pacemaker.yml
  120. when: openshift.common.rolling_restart_mode == 'system'
  121. - include: restart_services_pacemaker.yml
  122. when: openshift.common.rolling_restart_mode == 'services'
  123. - name: Restart current masters
  124. hosts: oo_current_masters
  125. serial: 1
  126. tasks:
  127. - include: restart_hosts.yml
  128. when: openshift.common.rolling_restart_mode == 'system'
  129. - include: restart_services.yml
  130. when: openshift.common.rolling_restart_mode == 'services'