migrate.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---
  2. - include: ../openshift-cluster/initialize_groups.yml
  3. tags:
  4. - always
  5. - include: ../../common/openshift-cluster/evaluate_groups.yml
  6. tags:
  7. - always
  8. - name: Run pre-checks
  9. hosts: oo_etcd_to_config
  10. tags:
  11. - always
  12. roles:
  13. - role: etcd_migrate
  14. r_etcd_migrate_action: check
  15. etcd_peer: "{{ ansible_default_ipv4.address }}"
  16. # TODO(jchaloup): replace the std_include with something minimal so the entire playbook is faster
  17. # e.g. I don't need to detect the OCP version, install deps, etc.
  18. - include: ../../common/openshift-cluster/std_include.yml
  19. tags:
  20. - always
  21. - name: Backup v2 data
  22. hosts: oo_etcd_to_config
  23. gather_facts: no
  24. tags:
  25. - always
  26. roles:
  27. - role: openshift_facts
  28. - role: etcd_common
  29. r_etcd_common_action: backup
  30. r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
  31. r_etcd_common_backup_tag: pre-migration
  32. r_etcd_common_embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  33. r_etcd_common_backup_sufix_name: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  34. - name: Gate on etcd backup
  35. hosts: localhost
  36. connection: local
  37. become: no
  38. tasks:
  39. - set_fact:
  40. etcd_backup_completed: "{{ hostvars
  41. | oo_select_keys(groups.oo_etcd_to_config)
  42. | oo_collect('inventory_hostname', {'r_etcd_common_backup_complete': true}) }}"
  43. - set_fact:
  44. etcd_backup_failed: "{{ groups.oo_etcd_to_config | difference(etcd_backup_completed) }}"
  45. - fail:
  46. msg: "Migration cannot continue. The following hosts did not complete etcd backup: {{ etcd_backup_failed | join(',') }}"
  47. when:
  48. - etcd_backup_failed | length > 0
  49. - name: Prepare masters for etcd data migration
  50. hosts: oo_masters_to_config
  51. tasks:
  52. - set_fact:
  53. master_services:
  54. - "{{ openshift.common.service_type + '-master' }}"
  55. - set_fact:
  56. master_services:
  57. - "{{ openshift.common.service_type + '-master-controllers' }}"
  58. - "{{ openshift.common.service_type + '-master-api' }}"
  59. when:
  60. - (openshift_master_cluster_method is defined and openshift_master_cluster_method == "native") or openshift.common.is_master_system_container | bool
  61. - debug:
  62. msg: "master service name: {{ master_services }}"
  63. - name: Stop masters
  64. service:
  65. name: "{{ item }}"
  66. state: stopped
  67. with_items: "{{ master_services }}"
  68. - name: Migrate etcd data from v2 to v3
  69. hosts: oo_etcd_to_config
  70. gather_facts: no
  71. tags:
  72. - always
  73. roles:
  74. - role: etcd_migrate
  75. r_etcd_migrate_action: migrate
  76. etcd_peer: "{{ ansible_default_ipv4.address }}"
  77. - name: Gate on etcd migration
  78. hosts: oo_masters_to_config
  79. gather_facts: no
  80. tasks:
  81. - set_fact:
  82. etcd_migration_completed: "{{ hostvars
  83. | oo_select_keys(groups.oo_etcd_to_config)
  84. | oo_collect('inventory_hostname', {'r_etcd_migrate_success': true}) }}"
  85. - set_fact:
  86. etcd_migration_failed: "{{ groups.oo_etcd_to_config | difference(etcd_migration_completed) }}"
  87. - name: Configure masters if etcd data migration is succesfull
  88. hosts: oo_masters_to_config
  89. roles:
  90. - role: etcd_migrate
  91. r_etcd_migrate_action: configure
  92. when: etcd_migration_failed | length == 0
  93. tasks:
  94. - debug:
  95. msg: "Skipping master re-configuration since migration failed."
  96. when:
  97. - etcd_migration_failed | length > 0
  98. - name: Start masters after etcd data migration
  99. hosts: oo_masters_to_config
  100. tasks:
  101. - name: Start master services
  102. service:
  103. name: "{{ item }}"
  104. state: started
  105. register: service_status
  106. # Sometimes the master-api, resp. master-controllers fails to start for the first time
  107. until: service_status.state is defined and service_status.state == "started"
  108. retries: 5
  109. delay: 10
  110. with_items: "{{ master_services[::-1] }}"
  111. - fail:
  112. msg: "Migration failed. The following hosts were not properly migrated: {{ etcd_migration_failed | join(',') }}"
  113. when:
  114. - etcd_migration_failed | length > 0