Added custom context name
Signed-off-by: Vivek Sarin <vivek@sarin.info>
This commit is contained in:
parent
6c14e5d923
commit
4063ea5ea1
|
@ -20,6 +20,7 @@ k3s_cluster:
|
||||||
extra_agent_args: ""
|
extra_agent_args: ""
|
||||||
|
|
||||||
# Optional vars
|
# Optional vars
|
||||||
|
# cluster_context: k3s-ansible
|
||||||
# api_port: 6443
|
# api_port: 6443
|
||||||
# k3s_server_location: /var/lib/rancher/k3s
|
# k3s_server_location: /var/lib/rancher/k3s
|
||||||
# systemd_dir: /etc/systemd/system
|
# systemd_dir: /etc/systemd/system
|
||||||
|
|
|
@ -4,3 +4,4 @@ systemd_dir: "/etc/systemd/system"
|
||||||
api_port: 6443
|
api_port: 6443
|
||||||
kubeconfig: ~/.kube/config.new
|
kubeconfig: ~/.kube/config.new
|
||||||
user_kubectl: true
|
user_kubectl: true
|
||||||
|
cluster_context: k3s-ansible
|
||||||
|
|
|
@ -120,12 +120,12 @@
|
||||||
changed_when:
|
changed_when:
|
||||||
- csa_result.rc == 0
|
- csa_result.rc == 0
|
||||||
|
|
||||||
- name: Setup kubeconfig k3s-ansible context on control node
|
- name: Setup kubeconfig {{ cluster_context }} context on control node
|
||||||
when: kubeconfig != "~/.kube/config"
|
when: kubeconfig != "~/.kube/config"
|
||||||
ansible.builtin.replace:
|
ansible.builtin.replace:
|
||||||
path: "{{ kubeconfig }}"
|
path: "{{ kubeconfig }}"
|
||||||
regexp: 'name: default'
|
regexp: 'name: default'
|
||||||
replace: 'name: k3s-ansible'
|
replace: 'name: {{ cluster_context }}'
|
||||||
delegate_to: 127.0.0.1
|
delegate_to: 127.0.0.1
|
||||||
become: false
|
become: false
|
||||||
|
|
||||||
|
@ -133,7 +133,8 @@
|
||||||
when: kubeconfig != "~/.kube/config"
|
when: kubeconfig != "~/.kube/config"
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
TFILE=$(mktemp)
|
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 use-context {{cluster_context}}
|
||||||
KUBECONFIG={{ kubeconfig }} kubectl config view --flatten > ${TFILE}
|
KUBECONFIG={{ kubeconfig }} kubectl config view --flatten > ${TFILE}
|
||||||
mv ${TFILE} {{ kubeconfig }}
|
mv ${TFILE} {{ kubeconfig }}
|
||||||
delegate_to: 127.0.0.1
|
delegate_to: 127.0.0.1
|
||||||
|
|
Loading…
Reference in New Issue