summaryrefslogtreecommitdiffstats
path: root/playbooks/openshift-etcd/private/embedded2external.yml
blob: 514319b88805762acf7980b880b590d5d7d78742 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
- name: Pre-migrate checks
  hosts: localhost
  tasks:
  # Check there is only one etcd host
  - assert:
      that: groups.oo_etcd_to_config | default([]) | length == 1
      msg: "[etcd] group must contain only one host"
  # Check there is only one master
  - assert:
      that: groups.oo_masters_to_config | default([]) | length == 1
      msg: "[master] group must contain only one host"

# 1. stop a master
- name: Prepare masters for etcd data migration
  hosts: oo_first_master
  roles:
  - role: openshift_facts
  tasks:
  - name: Check the master API is ready
    include_role:
      name: openshift_master
      tasks_from: check_master_api_is_ready
  - set_fact:
      master_service: "{{ openshift.common.service_type + '-master' }}"
      embedded_etcd_backup_suffix: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"
  - debug:
      msg: "master service name: {{ master_service }}"
  - name: Stop master
    service:
      name: "{{ master_service }}"
      state: stopped
  # 2. backup embedded etcd
  # Can't use with_items with include_role: https://github.com/ansible/ansible/issues/21285
  - include_role:
      name: etcd
      tasks_from: backup
    vars:
      r_etcd_common_backup_tag: pre-migrate
      r_etcd_common_embedded_etcd: "{{ true }}"
      r_etcd_common_backup_sufix_name: "{{ embedded_etcd_backup_suffix }}"

  - include_role:
      name: etcd
      tasks_from: backup.archive
    vars:
      r_etcd_common_backup_tag: pre-migrate
      r_etcd_common_embedded_etcd: "{{ true }}"
      r_etcd_common_backup_sufix_name: "{{ embedded_etcd_backup_suffix }}"

# 3. deploy certificates (for etcd and master)
- import_playbook: ca.yml

- import_playbook: server_certificates.yml

- name: Backup etcd client certificates for master host
  hosts: oo_first_master
  tasks:
  - include_role:
      name: etcd
      tasks_from: backup_master_etcd_certificates

- name: Redeploy master etcd certificates
  import_playbook: master_etcd_certificates.yml
  vars:
    etcd_certificates_redeploy: "{{ true }}"

# 4. deploy external etcd
- import_playbook: config.yml

# 5. stop external etcd
- name: Cleanse etcd
  hosts: oo_etcd_to_config[0]
  gather_facts: no
  pre_tasks:
  - include_role:
      name: etcd
      tasks_from: disable_etcd
  - include_role:
      name: etcd
      tasks_from: clean_data

# 6. copy the embedded etcd backup to the external host
# TODO(jchaloup): if the etcd and first master are on the same host, just copy the directory
- name: Copy embedded etcd backup to the external host
  hosts: localhost
  tasks:
  - name: Create local temp directory for syncing etcd backup
    local_action: command mktemp -d /tmp/etcd_backup-XXXXXXX
    register: g_etcd_client_mktemp
    changed_when: False
    become: no

  - include_role:
      name: etcd
      tasks_from: backup.fetch
    vars:
      etcd_backup_sync_directory: "{{ g_etcd_client_mktemp.stdout }}"
      r_etcd_common_backup_tag: pre-migrate
      r_etcd_common_embedded_etcd: "{{ true }}"
      r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"
    delegate_to: "{{ groups.oo_first_master[0] }}"

  - include_role:
      name: etcd
      tasks_from: backup.copy
    vars:
      etcd_backup_sync_directory: "{{ g_etcd_client_mktemp.stdout }}"
      r_etcd_common_backup_tag: pre-migrate
      r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"
    delegate_to: "{{ groups.oo_etcd_to_config[0] }}"

  - debug:
      msg: "etcd_backup_dest_directory: {{ g_etcd_client_mktemp.stdout }}"

  - name: Delete temporary directory
    local_action: file path="{{ g_etcd_client_mktemp.stdout }}" state=absent
    changed_when: False
    become: no

# 7. force new cluster from the backup
- name: Force new etcd cluster
  hosts: oo_etcd_to_config[0]
  tasks:
  - include_role:
      name: etcd
      tasks_from: backup.unarchive
    vars:
      r_etcd_common_backup_tag: pre-migrate
      r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"

  - include_role:
      name: etcd
      tasks_from: backup.force_new_cluster
    vars:
      r_etcd_common_backup_tag: pre-migrate
      r_etcd_common_backup_sufix_name: "{{ hostvars[groups.oo_first_master.0].embedded_etcd_backup_suffix }}"
      etcd_peer: "{{ openshift.common.ip }}"
      etcd_url_scheme: "https"
      etcd_peer_url_scheme: "https"

# 8. re-configure master to use the external etcd
- name: Configure master to use external etcd
  hosts: oo_first_master
  tasks:
  - include_role:
      name: openshift_master
      tasks_from: configure_external_etcd
    vars:
      etcd_peer_url_scheme: "https"
      etcd_ip: "{{ hostvars[groups.oo_etcd_to_config.0].openshift.common.ip }}"
      etcd_peer_port: 2379

  # 9. start the master
  - name: Start master
    service:
      name: "{{ master_service }}"
      state: started
    register: service_status
    until: service_status.state is defined and service_status.state == "started"
    retries: 5
    delay: 10