migrate.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. ---
  2. - name: Check if the master has embedded etcd
  3. hosts: localhost
  4. connection: local
  5. become: no
  6. gather_facts: no
  7. tags:
  8. - always
  9. tasks:
  10. - fail:
  11. msg: "Migration of an embedded etcd is not supported. Please, migrate the embedded etcd into an external etcd first."
  12. when:
  13. - groups.oo_etcd_to_config | default([]) | length == 0
  14. - name: Run pre-checks
  15. hosts: oo_etcd_to_migrate
  16. tasks:
  17. - include_role:
  18. name: etcd
  19. tasks_from: migrate.pre_check
  20. vars:
  21. r_etcd_common_embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  22. etcd_peer: "{{ ansible_default_ipv4.address }}"
  23. # TODO: This will be different for release-3.6 branch
  24. - name: Prepare masters for etcd data migration
  25. hosts: oo_masters_to_config
  26. tasks:
  27. - set_fact:
  28. master_services:
  29. - "{{ openshift.common.service_type + '-master-controllers' }}"
  30. - "{{ openshift.common.service_type + '-master-api' }}"
  31. - debug:
  32. msg: "master service name: {{ master_services }}"
  33. - name: Stop masters
  34. service:
  35. name: "{{ item }}"
  36. state: stopped
  37. with_items: "{{ master_services }}"
  38. - name: Backup v2 data
  39. hosts: oo_etcd_to_migrate
  40. gather_facts: no
  41. roles:
  42. - role: openshift_facts
  43. post_tasks:
  44. - include_role:
  45. name: etcd
  46. tasks_from: backup
  47. vars:
  48. r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
  49. r_etcd_common_backup_tag: pre-migration
  50. r_etcd_common_embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  51. r_etcd_common_backup_sufix_name: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  52. - name: Gate on etcd backup
  53. hosts: localhost
  54. connection: local
  55. become: no
  56. tasks:
  57. - set_fact:
  58. etcd_backup_completed: "{{ hostvars
  59. | oo_select_keys(groups.oo_etcd_to_migrate)
  60. | oo_collect('inventory_hostname', {'r_etcd_common_backup_complete': true}) }}"
  61. - set_fact:
  62. etcd_backup_failed: "{{ groups.oo_etcd_to_migrate | difference(etcd_backup_completed) | list }}"
  63. - fail:
  64. msg: "Migration cannot continue. The following hosts did not complete etcd backup: {{ etcd_backup_failed | join(',') }}"
  65. when:
  66. - etcd_backup_failed | length > 0
  67. - name: Stop etcd
  68. hosts: oo_etcd_to_migrate
  69. gather_facts: no
  70. pre_tasks:
  71. - include_role:
  72. name: etcd
  73. tasks_from: disable_etcd
  74. vars:
  75. r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
  76. - name: Migrate data on first etcd
  77. hosts: oo_etcd_to_migrate[0]
  78. gather_facts: no
  79. tasks:
  80. - include_role:
  81. name: etcd
  82. tasks_from: migrate
  83. vars:
  84. r_etcd_common_embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  85. etcd_peer: "{{ openshift.common.ip }}"
  86. etcd_url_scheme: "https"
  87. etcd_peer_url_scheme: "https"
  88. - name: Clean data stores on remaining etcd hosts
  89. hosts: oo_etcd_to_migrate[1:]
  90. gather_facts: no
  91. tasks:
  92. - include_role:
  93. name: etcd
  94. tasks_from: clean_data
  95. vars:
  96. r_etcd_common_embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  97. etcd_peer: "{{ openshift.common.ip }}"
  98. etcd_url_scheme: "https"
  99. etcd_peer_url_scheme: "https"
  100. - name: Add etcd hosts
  101. delegate_to: localhost
  102. add_host:
  103. name: "{{ item }}"
  104. groups: oo_new_etcd_to_config
  105. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  106. ansible_become: "{{ g_sudo | default(omit) }}"
  107. with_items: "{{ groups.oo_etcd_to_migrate[1:] | default([]) }}"
  108. changed_when: no
  109. - name: Set success
  110. set_fact:
  111. r_etcd_migrate_success: true
  112. - include: ./scaleup.yml
  113. - name: Gate on etcd migration
  114. hosts: oo_masters_to_config
  115. gather_facts: no
  116. tasks:
  117. - set_fact:
  118. etcd_migration_completed: "{{ hostvars
  119. | oo_select_keys(groups.oo_etcd_to_migrate)
  120. | oo_collect('inventory_hostname', {'r_etcd_migrate_success': true}) }}"
  121. - set_fact:
  122. etcd_migration_failed: "{{ groups.oo_etcd_to_migrate | difference(etcd_migration_completed) | list }}"
  123. - name: Add TTLs on the first master
  124. hosts: oo_first_master[0]
  125. tasks:
  126. - include_role:
  127. name: etcd
  128. tasks_from: migrate.add_ttls
  129. vars:
  130. etcd_peer: "{{ hostvars[groups.oo_etcd_to_migrate.0].openshift.common.ip }}"
  131. etcd_url_scheme: "https"
  132. etcd_peer_url_scheme: "https"
  133. when: etcd_migration_failed | length == 0
  134. - name: Configure masters if etcd data migration is succesfull
  135. hosts: oo_masters_to_config
  136. tasks:
  137. - include_role:
  138. name: etcd
  139. tasks_from: migrate.configure_master
  140. when: etcd_migration_failed | length == 0
  141. - debug:
  142. msg: "Skipping master re-configuration since migration failed."
  143. when:
  144. - etcd_migration_failed | length > 0
  145. - name: Start master services
  146. service:
  147. name: "{{ item }}"
  148. state: started
  149. register: service_status
  150. # Sometimes the master-api, resp. master-controllers fails to start for the first time
  151. until: service_status.state is defined and service_status.state == "started"
  152. retries: 5
  153. delay: 10
  154. with_items: "{{ master_services[::-1] }}"
  155. - fail:
  156. msg: "Migration failed. The following hosts were not properly migrated: {{ etcd_migration_failed | join(',') }}"
  157. when:
  158. - etcd_migration_failed | length > 0