Add task to get kubernetes configuration to .kubeconfig.

This commit is contained in:
2025-07-16 20:14:58 +02:00
parent 6e929947f0
commit bc2518b4ba

View File

@ -151,8 +151,6 @@
tasks:
- name: Store the join commands as facts
set_fact:
# *** THIS IS THE FIX ***
# Add the --control-plane flag to the join command for control planes.
join_cp_command: "{{ hostvars[groups['control_planes'][0]]['join_command_control_plane']['stdout'] }} --control-plane --certificate-key {{ hostvars[groups['control_planes'][0]]['cert_key']['stdout_lines'][-1] }}"
join_worker_command: "{{ hostvars[groups['control_planes'][0]]['join_command_control_plane']['stdout'] }}"
@ -179,3 +177,23 @@
command: "{{ hostvars['localhost']['join_worker_command'] }}"
args:
creates: /etc/kubernetes/kubelet.conf
# ==============================================================================
# PHASE 5: Fetch kubeconfig for local use
# ==============================================================================
- name: 5. Fetch admin.conf to the local machine
hosts: control_planes[0]
become: yes
tasks:
- name: Fetch admin.conf from the first control plane
fetch:
src: /etc/kubernetes/admin.conf
dest: .kubeconfig
flat: yes
- name: Update kubeconfig to use the cluster's external IP
replace:
path: .kubeconfig
regexp: 'https://192.168.122.101:6443'
replace: "https://{{ apiserver_endpoint }}:6443"
delegate_to: localhost