From 4d3b6341a9a758980cadb270acb7a2f3ac83c9e4 Mon Sep 17 00:00:00 2001 From: srwadleigh <7832+srwadleigh@users.noreply.github.com> Date: Fri, 7 Jun 2024 02:20:27 +0000 Subject: [PATCH] update homedir variable in get-kubeconf task, update task names, add k8s_get_kubeconf hook to skip fetching the kubeconf --- defaults/main.yml | 3 +++ tasks/main.yml | 3 ++- tasks/shared/charts.yml | 2 +- tasks/shared/kubeconf.yml | 12 ++++++------ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 0243888..98f1b96 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -36,6 +36,9 @@ k8s_taint_servers: false # apply label role=agent to agent nodes k8s_label_agents: false +# fetch kubeconfig from the bootstrap node +k8s_get_kubeconfig: true + # shared k8s api port k8s_api_port: 6443 diff --git a/tasks/main.yml b/tasks/main.yml index 5876393..4c3ed4b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -110,9 +110,10 @@ ansible.builtin.include_tasks: "shared/kubeconf.yml" when: - k8s_node_type == "bootstrap" + - k8s_get_kubeconf tags: - k8s-get-kubeconf - + - name: include secret block ansible.builtin.include_tasks: "shared/secrets.yml" when: diff --git a/tasks/shared/charts.yml b/tasks/shared/charts.yml index df7f601..b839d05 100644 --- a/tasks/shared/charts.yml +++ b/tasks/shared/charts.yml @@ -18,7 +18,7 @@ - name: install helm ansible.builtin.shell: "{{ k8s_helm_install_script }}" - - name: Add chart repos + - name: add chart repos kubernetes.core.helm_repository: name: "{{ item.repo_name }}" repo_url: "{{ item.repo_url }}" diff --git a/tasks/shared/kubeconf.yml b/tasks/shared/kubeconf.yml index 93ba735..f0ae6f9 100644 --- a/tasks/shared/kubeconf.yml +++ b/tasks/shared/kubeconf.yml @@ -9,15 +9,15 @@ - name: fetch kubeconfig ansible.builtin.fetch: src: "{{ k8s_config_path }}/{{ k8s_type }}.yaml" - dest: "~/.kube/config-{{ k8s_cluster_name }}.yaml" + dest: "$HOME/.kube/config-{{ k8s_cluster_name }}.yaml" flat: yes - - name: Update k8s Local Config + - name: update local kubeconfig delegate_to: localhost connection: local become: false ansible.builtin.shell: | - yq e '.clusters[].name = "{{ k8s_cluster_name }}"' -i ~/.kube/config-{{ k8s_cluster_name }}.yaml - yq e '.contexts[].name = "{{ k8s_cluster_context | d(k8s_cluster_name) }}"' -i ~/.kube/config-{{ k8s_cluster_name }}.yaml - yq e '(.clusters[] | select(.name == "{{ k8s_cluster_name }}")).cluster.server = "https://{{ k8s_cluster_url }}:{{ k8s_api_port }}"' -i ~/.kube/config-{{ k8s_cluster_name }}.yaml - yq e '(.contexts[] | select(.name == "{{ k8s_cluster_name }}")).context.cluster = "{{ k8s_cluster_name }}"' -i ~/.kube/config-{{ k8s_cluster_name }}.yaml + yq e '.clusters[].name = "{{ k8s_cluster_name }}"' -i $HOME/.kube/config-{{ k8s_cluster_name }}.yaml + yq e '.contexts[].name = "{{ k8s_cluster_context | d(k8s_cluster_name) }}"' -i $HOME/.kube/config-{{ k8s_cluster_name }}.yaml + yq e '(.clusters[] | select(.name == "{{ k8s_cluster_name }}")).cluster.server = "https://{{ k8s_cluster_url }}:{{ k8s_api_port }}"' -i $HOME/.kube/config-{{ k8s_cluster_name }}.yaml + yq e '(.contexts[] | select(.name == "{{ k8s_cluster_name }}")).context.cluster = "{{ k8s_cluster_name }}"' -i $HOME/.kube/config-{{ k8s_cluster_name }}.yaml