From ccd30b78abe123544738337ca9a32212c55b2347 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Mon, 11 Mar 2024 22:11:11 +0100 Subject: [PATCH] Add manager/copy-kubeconfig play (#388) This play copies the kubeconfig to the configuraton repository. Signed-off-by: Christian Berendt --- playbooks/manager-copy-kubeconfig.yml | 1 + playbooks/manager/copy-kubeconfig.yml | 30 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 120000 playbooks/manager-copy-kubeconfig.yml create mode 100644 playbooks/manager/copy-kubeconfig.yml diff --git a/playbooks/manager-copy-kubeconfig.yml b/playbooks/manager-copy-kubeconfig.yml new file mode 120000 index 00000000..0ba41c9e --- /dev/null +++ b/playbooks/manager-copy-kubeconfig.yml @@ -0,0 +1 @@ +manager/copy-kubeconfig.yml \ No newline at end of file diff --git a/playbooks/manager/copy-kubeconfig.yml b/playbooks/manager/copy-kubeconfig.yml new file mode 100644 index 00000000..265cfbb3 --- /dev/null +++ b/playbooks/manager/copy-kubeconfig.yml @@ -0,0 +1,30 @@ +--- +- name: Copy kubeconfig to the configuration repository + hosts: manager + gather_facts: false + + vars: + configuration_directory: /opt/configuration + + tasks: + - name: Get kubeconfig file + become: true + ansible.builtin.slurp: + src: /etc/rancher/k3s/k3s.yaml + delegate_to: "{{ groups[hosts_k3s_master | default('k3s_master')][0] }}" + register: kubeconfig + + - name: Write kubeconfig file + ansible.builtin.copy: + content: "{{ kubeconfig['content'] | b64decode }}" + dest: "{{ configuration_directory }}/environments/kolla/files/overlays/magnum/kubeconfig" + mode: 0640 + owner: dragon + group: dragon + + - name: Change server address in the kubeconfig file + ansible.builtin.lineinfile: + path: "{{ configuration_directory }}/environments/kolla/files/overlays/magnum/kubeconfig" + regexp: "^(.*server: https://)127.0.0.1(:6443)" + line: \g<1>{{ apiserver_endpoint }}\g<2> + backrefs: yes