From 060362178d609b2ad695fbd43afdf0bc3a918d33 Mon Sep 17 00:00:00 2001 From: Nick To Date: Mon, 5 Feb 2024 22:10:45 +0200 Subject: [PATCH] Fix unexpected behaviour when `kubeconfig` is set (#296) As detailed in https://github.com/k3s-io/k3s-ansible/issues/295, this commit fixes the issue that if `kubeconfig` is set to anything other than the defaults value, then: - `~/.kube/config` is modified. - No file at `{{ kubeconfig }}` is created. - Any existing file and `{{ kubeconfig }}` is deleted. Signed-off-by: Nick To --- roles/k3s_server/tasks/main.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/roles/k3s_server/tasks/main.yml b/roles/k3s_server/tasks/main.yml index 27e4332..412b526 100644 --- a/roles/k3s_server/tasks/main.yml +++ b/roles/k3s_server/tasks/main.yml @@ -119,9 +119,8 @@ ansible.builtin.shell: | TFILE=$(mktemp) KUBECONFIG={{ kubeconfig }} kubectl config set-context k3s-ansible --user=k3s-ansible --cluster=k3s-ansible - KUBECONFIG={{ kubeconfig }}:~/.kube/config kubectl config view --flatten > ${TFILE} - mv ${TFILE} ~/.kube/config - rm {{ kubeconfig }} + KUBECONFIG={{ kubeconfig }} kubectl config view --flatten > ${TFILE} + mv ${TFILE} {{ kubeconfig }} delegate_to: 127.0.0.1 become: false register: mv_result