migrate.yml 5.0 KB

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