migrate.yml 3.9 KB

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