Unverified Commit c84c1ce5 authored by Vivek Sarin's avatar Vivek Sarin Committed by GitHub
Browse files

Added custom context name (#315)



* Added custom context name

Signed-off-by: default avatarVivek Sarin <vivek@sarin.info>
Signed-off-by: default avatarDerek Nola <derek.nola@suse.com>
Co-authored-by: default avatarVivek Sarin <vivek@sarin.info>
Co-authored-by: default avatarDerek Nola <derek.nola@suse.com>
parent 6c14e5d9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ k3s_cluster:
    extra_agent_args: ""

  # Optional vars
    # cluster_context: k3s-ansible
    # api_port: 6443
    # k3s_server_location: /var/lib/rancher/k3s
    # systemd_dir: /etc/systemd/system
+1 −0
Original line number Diff line number Diff line
@@ -4,3 +4,4 @@ systemd_dir: "/etc/systemd/system"
api_port: 6443
kubeconfig: ~/.kube/config.new
user_kubectl: true
cluster_context: k3s-ansible
+3 −3
Original line number Diff line number Diff line
@@ -120,12 +120,12 @@
          changed_when:
            - csa_result.rc == 0

        - name: Setup kubeconfig k3s-ansible context on control node
        - name: Setup kubeconfig context on control node - {{ cluster_context }}
          when: kubeconfig != "~/.kube/config"
          ansible.builtin.replace:
            path: "{{ kubeconfig }}"
            regexp: 'name: default'
            replace: 'name: k3s-ansible'
            replace: 'name: {{ cluster_context }}'
          delegate_to: 127.0.0.1
          become: false

@@ -133,7 +133,7 @@
          when: kubeconfig != "~/.kube/config"
          ansible.builtin.shell: |
            TFILE=$(mktemp)
            KUBECONFIG={{ kubeconfig }} kubectl config set-context k3s-ansible --user=k3s-ansible --cluster=k3s-ansible
            KUBECONFIG={{ kubeconfig }} kubectl config set-context {{ cluster_context }} --user={{ cluster_context }} --cluster={{ cluster_context }}
            KUBECONFIG={{ kubeconfig }} kubectl config view --flatten > ${TFILE}
            mv ${TFILE} {{ kubeconfig }}
          delegate_to: 127.0.0.1