embedded2external.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. ---
  2. - name: Pre-migrate checks
  3. hosts: localhost
  4. tasks:
  5. # Check there is only one etcd host
  6. - assert:
  7. that: groups.oo_etcd_to_config | default([]) | length == 1
  8. msg: "[etcd] group must contain only one host"
  9. # Check there is only one master
  10. - assert:
  11. that: groups.oo_masters_to_config | default([]) | length == 1
  12. msg: "[master] group must contain only one host"
  13. # 1. stop a master
  14. - name: Prepare masters for etcd data migration
  15. hosts: oo_first_master
  16. roles:
  17. - role: openshift_facts
  18. tasks:
  19. - name: Check the master API is ready
  20. import_role:
  21. name: openshift_master
  22. tasks_from: check_master_api_is_ready.yml
  23. - set_fact:
  24. master_service: "{{ openshift_service_type + '-master' }}"
  25. embedded_etcd_backup_suffix: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  26. - debug:
  27. msg: "master service name: {{ master_service }}"
  28. - name: Stop master
  29. service:
  30. name: "{{ master_service }}"
  31. state: stopped
  32. # 2. backup embedded etcd
  33. # Can't use with_items with import_role: https://github.com/ansible/ansible/issues/21285
  34. - import_role:
  35. name: etcd
  36. tasks_from: backup.yml
  37. vars:
  38. r_etcd_common_backup_tag: pre-migrate
  39. r_etcd_common_embedded_etcd: "{{ true }}"
  40. r_etcd_common_backup_sufix_name: "{{ embedded_etcd_backup_suffix }}"
  41. - import_role:
  42. name: etcd
  43. tasks_from: backup.archive.yml
  44. vars:
  45. r_etcd_common_backup_tag: pre-migrate
  46. r_etcd_common_embedded_etcd: "{{ true }}"
  47. r_etcd_common_backup_sufix_name: "{{ embedded_etcd_backup_suffix }}"
  48. # 3. deploy certificates (for etcd and master)
  49. - import_playbook: ca.yml
  50. - import_playbook: server_certificates.yml
  51. - name: Backup etcd client certificates for master host
  52. hosts: oo_first_master
  53. tasks:
  54. - import_role:
  55. name: etcd
  56. tasks_from: backup_master_etcd_certificates.yml
  57. - name: Redeploy master etcd certificates
  58. import_playbook: master_etcd_certificates.yml
  59. vars:
  60. etcd_certificates_redeploy: "{{ true }}"
  61. # 4. deploy external etcd
  62. - import_playbook: config.yml
  63. # 5. stop external etcd
  64. - name: Cleanse etcd
  65. hosts: oo_etcd_to_config[0]
  66. gather_facts: no
  67. pre_tasks:
  68. - import_role:
  69. name: etcd
  70. tasks_from: disable_etcd.yml
  71. - import_role:
  72. name: etcd
  73. tasks_from: clean_data.yml
  74. # 6. copy the embedded etcd backup to the external host
  75. # TODO(jchaloup): if the etcd and first master are on the same host, just copy the directory
  76. - name: Copy embedded etcd backup to the external host
  77. hosts: localhost
  78. tasks:
  79. - name: Create local temp directory for syncing etcd backup
  80. local_action: command mktemp -d /tmp/etcd_backup-XXXXXXX
  81. register: g_etcd_client_mktemp
  82. changed_when: False
  83. - import_role:
  84. name: etcd
  85. tasks_from: backup.fetch.yml
  86. vars:
  87. etcd_backup_sync_directory: "{{ g_etcd_client_mktemp.stdout }}"
  88. r_etcd_common_backup_tag: pre-migrate
  89. r_etcd_common_embedded_etcd: "{{ true }}"
  90. r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"
  91. delegate_to: "{{ groups.oo_first_master[0] }}"
  92. - import_role:
  93. name: etcd
  94. tasks_from: backup.copy.yml
  95. vars:
  96. etcd_backup_sync_directory: "{{ g_etcd_client_mktemp.stdout }}"
  97. r_etcd_common_backup_tag: pre-migrate
  98. r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"
  99. delegate_to: "{{ groups.oo_etcd_to_config[0] }}"
  100. - debug:
  101. msg: "etcd_backup_dest_directory: {{ g_etcd_client_mktemp.stdout }}"
  102. - name: Delete temporary directory
  103. local_action: file path="{{ g_etcd_client_mktemp.stdout }}" state=absent
  104. changed_when: False
  105. # 7. force new cluster from the backup
  106. - name: Force new etcd cluster
  107. hosts: oo_etcd_to_config[0]
  108. tasks:
  109. - import_role:
  110. name: etcd
  111. tasks_from: backup.unarchive.yml
  112. vars:
  113. r_etcd_common_backup_tag: pre-migrate
  114. r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"
  115. - import_role:
  116. name: etcd
  117. tasks_from: backup.force_new_cluster.yml
  118. vars:
  119. r_etcd_common_backup_tag: pre-migrate
  120. r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"
  121. etcd_peer: "{{ openshift.common.ip }}"
  122. etcd_url_scheme: "https"
  123. etcd_peer_url_scheme: "https"
  124. # 8. re-configure master to use the external etcd
  125. - name: Configure master to use external etcd
  126. hosts: oo_first_master
  127. tasks:
  128. - import_role:
  129. name: openshift_master
  130. tasks_from: configure_external_etcd.yml
  131. vars:
  132. etcd_peer_url_scheme: "https"
  133. etcd_ip: "{{ hostvars[groups.oo_etcd_to_config.0].openshift.common.ip }}"
  134. etcd_peer_port: 2379
  135. # 9. start the master
  136. - name: Start master
  137. service:
  138. name: "{{ master_service }}"
  139. state: started
  140. register: service_status
  141. until: service_status.state is defined and service_status.state == "started"
  142. retries: 5
  143. delay: 10