restart.yml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 after this system has been restarted and services
  56. must be verified manually. To only restart services, set
  57. openshift_master_rolling_restart_mode=services in host
  58. inventory and relaunch the playbook.
  59. when: exists.stat.exists and openshift.common.rolling_restart_mode == 'system'
  60. - set_fact:
  61. current_host: "{{ exists.stat.exists }}"
  62. when: openshift.common.rolling_restart_mode == 'system'
  63. - name: Determine which masters are currently active
  64. hosts: oo_masters_to_config
  65. tasks:
  66. - name: Check master service status
  67. command: >
  68. systemctl is-active {{ openshift.common.service_type }}-master
  69. register: active_check_output
  70. when: openshift.master.cluster_method == 'pacemaker'
  71. failed_when: active_check_output.stdout not in ['active', 'inactive']
  72. changed_when: false
  73. - set_fact:
  74. is_active: "{{ active_check_output.stdout == 'active' }}"
  75. when: openshift.master.cluster_method == 'pacemaker'
  76. - name: Evaluate master groups
  77. hosts: localhost
  78. become: no
  79. tasks:
  80. - name: Evaluate oo_active_masters
  81. add_host:
  82. name: "{{ item }}"
  83. groups: oo_active_masters
  84. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  85. ansible_sudo: "{{ g_sudo | default(omit) }}"
  86. with_items: "{{ groups.oo_masters_to_config | default([]) }}"
  87. when: (hostvars[item]['is_active'] | default(false)) | bool
  88. - name: Evaluate oo_current_masters
  89. add_host:
  90. name: "{{ item }}"
  91. groups: oo_current_masters
  92. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  93. ansible_sudo: "{{ g_sudo | default(omit) }}"
  94. with_items: "{{ groups.oo_masters_to_config | default([]) }}"
  95. when: (hostvars[item]['current_host'] | default(false)) | bool
  96. - name: Validate pacemaker cluster
  97. hosts: oo_active_masters
  98. tasks:
  99. - name: Retrieve pcs status
  100. command: pcs status
  101. register: pcs_status_output
  102. changed_when: false
  103. - fail:
  104. msg: >
  105. Pacemaker cluster validation failed. One or more nodes are not online.
  106. when: not (pcs_status_output.stdout | validate_pcs_cluster(groups.oo_masters_to_config)) | bool
  107. - name: Restart masters
  108. hosts: oo_masters_to_config:!oo_active_masters:!oo_current_masters
  109. vars:
  110. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  111. serial: 1
  112. tasks:
  113. - include: restart_hosts.yml
  114. when: openshift.common.rolling_restart_mode == 'system'
  115. - include: restart_services.yml
  116. when: openshift.common.rolling_restart_mode == 'services'
  117. - name: Restart active masters
  118. hosts: oo_active_masters
  119. serial: 1
  120. tasks:
  121. - include: restart_hosts_pacemaker.yml
  122. when: openshift.common.rolling_restart_mode == 'system'
  123. - include: restart_services_pacemaker.yml
  124. when: openshift.common.rolling_restart_mode == 'services'
  125. - name: Restart current masters
  126. hosts: oo_current_masters
  127. serial: 1
  128. tasks:
  129. - include: restart_hosts.yml
  130. when: openshift.common.rolling_restart_mode == 'system'
  131. - include: restart_services.yml
  132. when: openshift.common.rolling_restart_mode == 'services'