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: Prepare masters for etcd data migration
  18. hosts: oo_masters_to_config
  19. tasks:
  20. - set_fact:
  21. master_services:
  22. - "{{ openshift.common.service_type + '-master' }}"
  23. - set_fact:
  24. master_services:
  25. - "{{ openshift.common.service_type + '-master-controllers' }}"
  26. - "{{ openshift.common.service_type + '-master-api' }}"
  27. when:
  28. - (openshift_master_cluster_method is defined and openshift_master_cluster_method == "native") or openshift.common.is_master_system_container | bool
  29. - debug:
  30. msg: "master service name: {{ master_services }}"
  31. - name: Stop masters
  32. service:
  33. name: "{{ item }}"
  34. state: stopped
  35. with_items: "{{ master_services }}"
  36. - name: Backup v2 data
  37. hosts: oo_etcd_to_migrate
  38. gather_facts: no
  39. tags:
  40. - always
  41. roles:
  42. - role: openshift_facts
  43. - role: etcd_common
  44. r_etcd_common_action: backup
  45. r_etcd_common_etcd_runtime: "{{ openshift.common.etcd_runtime }}"
  46. r_etcd_common_backup_tag: pre-migration
  47. r_etcd_common_embedded_etcd: "{{ groups.oo_etcd_to_config | default([]) | length == 0 }}"
  48. r_etcd_common_backup_sufix_name: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  49. - name: Gate on etcd backup
  50. hosts: localhost
  51. connection: local
  52. become: no
  53. tasks:
  54. - set_fact:
  55. etcd_backup_completed: "{{ hostvars
  56. | oo_select_keys(groups.oo_etcd_to_migrate)
  57. | oo_collect('inventory_hostname', {'r_etcd_common_backup_complete': true}) }}"
  58. - set_fact:
  59. etcd_backup_failed: "{{ groups.oo_etcd_to_migrate | difference(etcd_backup_completed) }}"
  60. - fail:
  61. msg: "Migration cannot continue. The following hosts did not complete etcd backup: {{ etcd_backup_failed | join(',') }}"
  62. when:
  63. - etcd_backup_failed | length > 0
  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