Initial commit
This commit is contained in:
40
ansible/playbooks/k3s-distribute-kubeconfig.yml
Normal file
40
ansible/playbooks/k3s-distribute-kubeconfig.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
- name: Distribute kubeconfig to k3s server nodes
|
||||
hosts: k3s
|
||||
become: true
|
||||
|
||||
tasks:
|
||||
- name: Create .kube directory
|
||||
ansible.builtin.file:
|
||||
path: "~{{ ansible_user }}/.kube"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
|
||||
- name: Copy kubeconfig from local machine to remote host
|
||||
ansible.builtin.copy:
|
||||
src: "~/.kube/config"
|
||||
dest: "~{{ ansible_user }}/.kube/config"
|
||||
mode: '0600'
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
|
||||
- name: Set KUBECONFIG in ansible_user profile
|
||||
ansible.builtin.lineinfile:
|
||||
path: "~{{ ansible_user }}/.profile"
|
||||
line: "export KUBECONFIG=~{{ ansible_user }}/.kube/config"
|
||||
regexp: "^export KUBECONFIG=.*"
|
||||
create: true
|
||||
mode: '0644'
|
||||
owner: "{{ ansible_user }}"
|
||||
group: "{{ ansible_user }}"
|
||||
|
||||
- name: Verify kubectl works on remote host
|
||||
ansible.builtin.command: k3s kubectl get nodes
|
||||
register: nodes_result
|
||||
changed_when: false
|
||||
|
||||
- name: Display cluster nodes
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ nodes_result.stdout_lines }}"
|
||||
Reference in New Issue
Block a user