2019-04-29 08:40:20 +00:00
|
|
|
---
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: Save etcd snapshot
|
|
|
|
command: "{{ bin_dir }}/etcdctl snapshot save /tmp/snapshot.db"
|
2019-04-29 08:40:20 +00:00
|
|
|
environment:
|
2020-07-20 14:26:51 +00:00
|
|
|
- ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
- ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
|
|
|
- ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
|
|
|
- ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses.split(',') | first }}"
|
2019-04-29 08:40:20 +00:00
|
|
|
- ETCDCTL_API: 3
|
|
|
|
when: etcd_snapshot is not defined
|
|
|
|
|
|
|
|
- name: Transfer etcd snapshot to host
|
|
|
|
copy:
|
|
|
|
src: "{{ etcd_snapshot }}"
|
|
|
|
dest: /tmp/snapshot.db
|
2021-07-12 07:00:47 +00:00
|
|
|
mode: 0640
|
2019-04-29 08:40:20 +00:00
|
|
|
when: etcd_snapshot is defined
|
|
|
|
|
|
|
|
- name: Stop etcd
|
|
|
|
systemd:
|
|
|
|
name: etcd
|
|
|
|
state: stopped
|
|
|
|
|
|
|
|
- name: Remove etcd data-dir
|
2019-04-29 12:12:22 +00:00
|
|
|
file:
|
|
|
|
path: "{{ etcd_data_dir }}"
|
|
|
|
state: absent
|
2019-04-29 08:40:20 +00:00
|
|
|
|
2020-07-27 13:24:17 +00:00
|
|
|
- name: Restore etcd snapshot # noqa 301 305
|
2020-07-20 14:26:51 +00:00
|
|
|
shell: "{{ bin_dir }}/etcdctl snapshot restore /tmp/snapshot.db --name {{ etcd_member_name }} --initial-cluster {{ etcd_member_name }}={{ etcd_peer_url }} --initial-cluster-token k8s_etcd --initial-advertise-peer-urls {{ etcd_peer_url }} --data-dir {{ etcd_data_dir }}"
|
2019-04-29 08:40:20 +00:00
|
|
|
environment:
|
2020-07-20 14:26:51 +00:00
|
|
|
- ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
- ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
|
|
|
- ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
|
|
|
- ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
2019-04-29 08:40:20 +00:00
|
|
|
- ETCDCTL_API: 3
|
|
|
|
|
|
|
|
- name: Remove etcd snapshot
|
|
|
|
file:
|
|
|
|
path: /tmp/snapshot.db
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Change etcd data-dir owner
|
|
|
|
file:
|
|
|
|
path: "{{ etcd_data_dir }}"
|
|
|
|
owner: etcd
|
|
|
|
group: etcd
|
|
|
|
recurse: true
|
|
|
|
|
|
|
|
- name: Reconfigure etcd
|
|
|
|
replace:
|
|
|
|
path: /etc/etcd.env
|
|
|
|
regexp: "^(ETCD_INITIAL_CLUSTER=).*"
|
|
|
|
replace: '\1{{ etcd_member_name }}={{ etcd_peer_url }}'
|
|
|
|
|
|
|
|
- name: Start etcd
|
|
|
|
systemd:
|
|
|
|
name: etcd
|
|
|
|
state: started
|