kubekey/plugins/roles/etcd/restore/tasks/main.yaml
liujian fb474bde50
feat: change builtin defined variable (#2561)
* feat: change inventory_hosts to hostvars

Signed-off-by: joyceliu <joyceliu@yunify.com>

* feat: change inventory_hosts to hostvars

Signed-off-by: joyceliu <joyceliu@yunify.com>

---------

Signed-off-by: joyceliu <joyceliu@yunify.com>
2025-05-13 06:40:01 +00:00

32 lines
1.1 KiB
YAML

---
- name: Sync etcd snapshot to remote
copy:
src: "{{ .work_dir }}/kubekey/etcd/snapshot.db"
dest: /tmp/kubekey/etcd/snapshot.db
- name: Stop etcd
command: systemctl stop etcd
- name: Remove etcd data dir
command: |
rm -rf /var/lib/etcd/*
- name: Restore etcd by snapshot
command: |
export $(cat /etc/etcd.env | grep ETCDCTL_CACERT)
export $(cat /etc/etcd.env | grep ETCDCTL_CERT)
export $(cat /etc/etcd.env | grep ETCDCTL_KEY)
etcdctl snapshot restore /tmp/kubekey/etcd/snapshot.db \
--name={{ .inventory_hostname }} --endpoints=https://{{ .internal_ipv4 }}:2379 \
{{- $ips := list -}}
{{- range $element := .groups.etcd -}}
{{- $ips = append $ips (printf "%s=https://%s:2380" (index .hostvars $element "inventory_hostname") (index .hostvars $element "internal_ipv4") -}}
{{- end -}}
--initial-cluster={{ $ips | join "," }} \
--initial-advertise-peer-urls=https://{{ .internal_ipv4 }}:2380\
--initial-cluster-token={{ .etcd.env.token }} \
--data-dir={{ .etcd.env.data_dir }}
- name: Start etcd
command: systemctl start etcd