migrate.yml 5.1 KB

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