summaryrefslogtreecommitdiffstats
path: root/roles/etcd/tasks/migration/migrate.yml
blob: 630640ab1c7bd256cc64df14e66640205b2fc186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
# Should this be run in a serial manner?
- set_fact:
    l_etcd_service: "{{ 'etcd_container' if (openshift_is_containerized | bool) else 'etcd' }}"

- name: Migrate etcd data
  command: >
    etcdctl migrate --data-dir={{ etcd_data_dir }}
  environment:
    ETCDCTL_API: 3
  register: l_etcdctl_migrate
# TODO(jchaloup): If any of the members fails, we need to restore all members to v2 from the pre-migrate backup
- name: Check the etcd v2 data are correctly migrated
  fail:
    msg: "Failed to migrate a member"
  when: "'finished transforming keys' not in l_etcdctl_migrate.stdout and 'no v2 keys to migrate' not in l_etcdctl_migrate.stdout"
- name: Migration message
  debug:
    msg: "Etcd migration finished with: {{ l_etcdctl_migrate.stdout }}"
- name: Set ETCD_FORCE_NEW_CLUSTER=true on first etcd host
  lineinfile:
    line: "ETCD_FORCE_NEW_CLUSTER=true"
    dest: /etc/etcd/etcd.conf
    backup: true
- name: Start etcd
  systemd:
    name: "{{ l_etcd_service }}"
    state: started
- name: Wait for cluster to become healthy after bringing up first member
  command: >
    etcdctl --cert-file {{ etcd_peer_cert_file }} --key-file {{ etcd_peer_key_file }} --ca-file {{ etcd_peer_ca_file }} --endpoint https://{{ etcd_peer }}:{{ etcd_client_port }} cluster-health
  register: l_etcd_migrate_health
  until: l_etcd_migrate_health.rc == 0
  retries: 3
  delay: 30
- name: Unset ETCD_FORCE_NEW_CLUSTER=true on first etcd host
  lineinfile:
    line: "ETCD_FORCE_NEW_CLUSTER=true"
    dest: /etc/etcd/etcd.conf
    state: absent
    backup: true
- name: Restart first etcd host
  systemd:
    name: "{{ l_etcd_service }}"
    state: restarted

- name: Wait for cluster to become healthy after bringing up first member
  command: >
    etcdctl --cert-file {{ etcd_peer_cert_file }} --key-file {{ etcd_peer_key_file }} --ca-file {{ etcd_peer_ca_file }} --endpoint https://{{ etcd_peer }}:{{ etcd_client_port }} cluster-health
  register: l_etcd_migrate_health
  until: l_etcd_migrate_health.rc == 0
  retries: 3
  delay: 30

- set_fact:
    r_etcd_migrate_success: true