diff --git a/builtin/core/playbooks/add_nodes.yaml b/builtin/core/playbooks/add_nodes.yaml index 27a28e0d..22519097 100644 --- a/builtin/core/playbooks/add_nodes.yaml +++ b/builtin/core/playbooks/add_nodes.yaml @@ -31,7 +31,10 @@ # init os - hosts: + - etcd - k8s_cluster + - registry + - nfs roles: - init/init-os diff --git a/builtin/core/roles/init/init-os/tasks/init_localdns.yaml b/builtin/core/roles/init/init-os/tasks/init_localdns.yaml new file mode 100644 index 00000000..822e2d9f --- /dev/null +++ b/builtin/core/roles/init/init-os/tasks/init_localdns.yaml @@ -0,0 +1,49 @@ +- name: Set local DNS + command: | + # clear old dns configuration + sed -i ':a;$!{N;ba};s@# kubekey hosts BEGIN.*# kubekey hosts END@@' /etc/hosts + sed -i '/^$/N;/\n$/N;//D' /etc/hosts + # defined new dns configuration + cat >>/etc/hosts<>/etc/hosts< /proc/sys/vm/drop_caches diff --git a/plugins/roles/etcd/restore/tasks/main.yaml b/plugins/roles/etcd/restore/tasks/main.yaml index 51c614b2..01a4a7c0 100644 --- a/plugins/roles/etcd/restore/tasks/main.yaml +++ b/plugins/roles/etcd/restore/tasks/main.yaml @@ -19,8 +19,8 @@ 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") -}} + {{- range .groups.etcd -}} + {{- $ips = append $ips (printf "%s=https://%s:2380" . (index $.hostvars . "internal_ipv4") -}} {{- end -}} --initial-cluster={{ $ips | join "," }} \ --initial-advertise-peer-urls=https://{{ .internal_ipv4 }}:2380\