Added custom context name (#315)
* Added custom context name Signed-off-by: Vivek Sarin <vivek@sarin.info> Signed-off-by: Derek Nola <derek.nola@suse.com> Co-authored-by: Vivek Sarin <vivek@sarin.info> Co-authored-by: Derek Nola <derek.nola@suse.com>pull/322/head
parent
6c14e5d923
commit
c84c1ce5b1
|
@ -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
|
||||
|
|
|
@ -4,3 +4,4 @@ systemd_dir: "/etc/systemd/system"
|
|||
api_port: 6443
|
||||
kubeconfig: ~/.kube/config.new
|
||||
user_kubectl: true
|
||||
cluster_context: k3s-ansible
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue