summaryrefslogtreecommitdiffstats
path: root/roles/etcd/tasks/migration/check.yml
blob: 5c45e5ae1ba893c3a9654b81c757693c6ad21b08 (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
57
58
59
60
61
62
63
64
65
66
67
---

# Check the cluster is healthy
- include: check_cluster_health.yml

# Check if there is at least one v2 snapshot
- name: Check if there is at least one v2 snapshot
  find:
    paths: "{{ etcd_data_dir }}/member/snap"
    patterns: '*.snap'
  register: snapshots_result

- fail:
    msg: "Before the migration can proceed the etcd member must write down at least one snapshot under {{ etcd_data_dir }}/member/snap directory."
  when: snapshots_result.matched | int == 0

# Check if the member has v3 data already
# Run the migration only if the data are v2
- name: Check if there are any v3 data
  command: >
    etcdctl --cert {{ etcd_peer_cert_file }} --key {{ etcd_peer_key_file }} --cacert {{ etcd_peer_ca_file }} --endpoints 'https://{{ etcd_peer }}:{{ etcd_client_port }}' get "" --from-key --keys-only -w json --limit 1
  environment:
    ETCDCTL_API: 3
  register: l_etcdctl_output

- fail:
    msg: "Unable to get a number of v3 keys"
  when: l_etcdctl_output.rc != 0

- fail:
    msg: "The etcd has at least one v3 key"
  when: "'count' in (l_etcdctl_output.stdout | from_json) and (l_etcdctl_output.stdout | from_json).count != 0"


# TODO(jchaloup): once the until loop can be used over include/block,
#                 remove the repetive code
# - until loop not supported over include statement (nor block)
#   https://github.com/ansible/ansible/issues/17098
# - with_items not supported over block

# Check the cluster status for the first time
- include: check_cluster_status.yml

# Check the cluster status for the second time
- block:
  - debug:
      msg: "l_etcd_cluster_status_ok: {{ l_etcd_cluster_status_ok }}"
  - name: Wait a while before another check
    pause:
      seconds: 5
    when: not l_etcd_cluster_status_ok | bool

  - include: check_cluster_status.yml
    when: not l_etcd_cluster_status_ok | bool


# Check the cluster status for the third time
- block:
  - debug:
      msg: "l_etcd_cluster_status_ok: {{ l_etcd_cluster_status_ok }}"
  - name: Wait a while before another check
    pause:
      seconds: 5
    when: not l_etcd_cluster_status_ok | bool

  - include: check_cluster_status.yml
    when: not l_etcd_cluster_status_ok | bool