From 5fdb208d7edcf062ff1afd5a297f556d575cc4a2 Mon Sep 17 00:00:00 2001 From: Alexandru Mahmoud Date: Mon, 27 Jun 2022 21:26:36 -0400 Subject: [PATCH] Get external kubeconfig from rancher --- roles/cloudman-boot/tasks/auth.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/roles/cloudman-boot/tasks/auth.yaml b/roles/cloudman-boot/tasks/auth.yaml index 97541e8..b0c5734 100644 --- a/roles/cloudman-boot/tasks/auth.yaml +++ b/roles/cloudman-boot/tasks/auth.yaml @@ -205,3 +205,26 @@ retries: 5 delay: 10 tags: auth + + - name: Get external cluster kubeconfig + uri: + url: https://{{ rancher_hostname }}/v3/clusters/local?action=generateKubeconfig + method: POST + validate_certs: "{{ cm_validate_certs }}" + headers: + Authorization: Bearer {{ ra_token }} + register: kubeconfig_response + retries: 10 + delay: 2 + until: kubeconfig_response['status']|default(0) == 200 + tags: auth + + - name: Set external Kubeconfig + set_fact: + ex_kubeconfig: "{{ kubeconfig_response.json.config }}" + + - name: Save external kubeconfig to file + copy: + content: "{{ ex_kubeconfig }}" + dest: "/etc/rancher/rke2/external.yaml" + delegate_to: localhost