Fix kubelet.conf server line indentation (#13284)

The lineinfile tasks that rewrite the server field in kubelet.conf
replaced the whole line with a hard-coded indentation, corrupting the
file when the existing entry was indented differently. Capture the
original leading whitespace with a group regexp and restore it via
backrefs so the rewrite preserves the surrounding YAML structure.

Signed-off-by: longyuxiang <longyuxiang@kylinos.cn>
This commit is contained in:
longxiucai
2026-09-15 06:37:18 +00:00
committed by GitHub
parent b1b01bc579
commit 53a30aea58
+6 -4
View File
@@ -103,8 +103,9 @@
- name: Update server field in kubelet kubeconfig
lineinfile:
dest: "{{ kube_config_dir }}/kubelet.conf"
regexp: 'server:'
line: ' server: {{ kube_apiserver_endpoint }}'
regexp: '^(\s+)server: https.*'
line: '\1server: {{ kube_apiserver_endpoint }}'
backrefs: true
backup: true
when:
- kubeadm_config_api_fqdn is not defined
@@ -115,8 +116,9 @@
- name: Update server field in kubelet kubeconfig - external lb
lineinfile:
dest: "{{ kube_config_dir }}/kubelet.conf"
regexp: '^ server: https'
line: ' server: {{ kube_apiserver_endpoint }}'
regexp: '^(\s+)server: https.*'
line: '\1server: {{ kube_apiserver_endpoint }}'
backrefs: true
backup: true
when:
- ('kube_control_plane' not in group_names)