Skip to content

Commit

Permalink
Fix kubeconfig merge with existing config
Browse files Browse the repository at this point in the history
Signed-off-by: alankan-finocomp <[email protected]>
  • Loading branch information
alankan-finocomp authored Jul 25, 2024
1 parent b6e4c8b commit ca67c68
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@
when: kubeconfig != "~/.kube/config"
ansible.builtin.replace:
path: "{{ kubeconfig }}"
regexp: 'name: default'
replace: 'name: {{ cluster_context }}'
regexp: 'default'
replace: '{{ cluster_context }}'
delegate_to: 127.0.0.1
become: false

- name: Merge with any existing kubeconfig on control node
when: kubeconfig != "~/.kube/config"
ansible.builtin.shell: |
TFILE=$(mktemp)
KUBECONFIG={{ kubeconfig }} kubectl config set-context {{ cluster_context }} --user={{ cluster_context }} --cluster={{ cluster_context }}
KUBECONFIG={{ kubeconfig }} kubectl config view --flatten > ${TFILE}
KUBECONFIG={{ kubeconfig }}:~/.kube/config kubectl config set-context {{ cluster_context }} --user={{ cluster_context }} --cluster={{ cluster_context }}
KUBECONFIG={{ kubeconfig }}:~/.kube/config kubectl config view --flatten > ${TFILE}
mv ${TFILE} {{ kubeconfig }}
delegate_to: 127.0.0.1
become: false
Expand Down

0 comments on commit ca67c68

Please sign in to comment.