From 7a9cc7cc1c83fbe8b1a6db56053b2c4e45f06330 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Mon, 25 Apr 2022 23:05:18 +0200 Subject: [PATCH] Store kubeconfig in tempfile;Reference tempfile --- playbook.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/playbook.yml b/playbook.yml index a4062a4..d79a1a8 100644 --- a/playbook.yml +++ b/playbook.yml @@ -122,7 +122,7 @@ - name: Initial node -- Store token ansible.builtin.set_fact: - cluster: "{{ cluster | combine( { 'token': ( k3s_token.content | b64decode | trim ) }, { 'kubeconfig': ( k3s_kubeconfig.stdout | from_yaml ) } ) }}" + cluster: "{{ cluster | combine( { 'token': ( k3s_token.content | b64decode | trim ) }, { 'kubeconfig': ( k3s_kubeconfig.stdout ) } ) }}" - block: @@ -180,13 +180,16 @@ - applications.k3s.yml tasks: - - name: Retrieve cluster dict from initial node - ansible.builtin.debug: - msg: "{{ hostvars | dict2items }}" - - ansible.builtin.set_fact: - cluster: "{{ ( lookup('dict', hostvars) )[0].value.cluster }}" - - ansible.builtin.debug: - var: cluster + - name: Initialize tempfile + ansible.builtin.tempfile: + state: file + register: kubeconfig + + - name: Store kubeconfig in tempfile + ansible.builtin.copy: + dest: "{{ kubeconfig.path }}" + content: "{{ ( lookup('dict', hostvars) )[0].value.cluster.kubeconfig }}" + mode: 0600 - name: Add Helm chart repositories kubernetes.core.helm_repository: @@ -209,7 +212,7 @@ namespace: fleet-system create_namespace: yes wait: yes - kubeconfig: "{{ cluster.kubeconfig }}" + kubeconfig: "{{ kubeconfig.path }}" loop: - name: fleet-crd url: "https://github.com/rancher/fleet/releases/download/{{ latest_release.json.tag_name }}/fleet-crd-{{ latest_release.json.tag_name }}.tgz"