restart.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. - set_fact:
  71. is_active: "{{ active_check_output.stdout == 'active' }}"
  72. when: openshift.master.cluster_method == 'pacemaker'
  73. - name: Evaluate master groups
  74. hosts: localhost
  75. become: no
  76. tasks:
  77. - name: Evaluate oo_active_masters
  78. add_host:
  79. name: "{{ item }}"
  80. groups: oo_active_masters
  81. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  82. ansible_sudo: "{{ g_sudo | default(omit) }}"
  83. with_items: "{{ groups.oo_masters_to_config | default([]) }}"
  84. when: (hostvars[item]['is_active'] | default(false)) | bool
  85. - name: Evaluate oo_current_masters
  86. add_host:
  87. name: "{{ item }}"
  88. groups: oo_current_masters
  89. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  90. ansible_sudo: "{{ g_sudo | default(omit) }}"
  91. with_items: "{{ groups.oo_masters_to_config | default([]) }}"
  92. when: (hostvars[item]['current_host'] | default(false)) | bool
  93. - name: Restart masters
  94. hosts: oo_masters_to_config:!oo_active_masters:!oo_current_masters
  95. vars:
  96. openshift_master_ha: "{{ groups.oo_masters_to_config | length > 1 }}"
  97. serial: 1
  98. tasks:
  99. - include: restart_hosts.yml
  100. when: openshift.common.rolling_restart_mode == 'system'
  101. - include: restart_services.yml
  102. when: openshift.common.rolling_restart_mode == 'services'
  103. - name: Restart active masters
  104. hosts: oo_active_masters
  105. serial: 1
  106. tasks:
  107. - include: restart_hosts_pacemaker.yml
  108. when: openshift.common.rolling_restart_mode == 'system'
  109. - include: restart_services_pacemaker.yml
  110. when: openshift.common.rolling_restart_mode == 'services'
  111. - name: Restart current masters
  112. hosts: oo_current_masters
  113. serial: 1
  114. tasks:
  115. - include: restart_hosts.yml
  116. when: openshift.common.rolling_restart_mode == 'system'
  117. - include: restart_services.yml
  118. when: openshift.common.rolling_restart_mode == 'services'