Skip to content

Commit

Permalink
add: kubeconfig to all nodes (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
pasiol authored Jan 13, 2025
1 parent 8af477b commit 1d41754
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 23 deletions.
30 changes: 30 additions & 0 deletions roles/cluster_control_plane_init/tasks/kubeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Fetch cluster config
become: true
register: slurpfile
ansible.builtin.slurp:
src: /etc/kubernetes/admin.conf

- name: Ensure .kube directory exists
delegate_to: kvm_host_local
connection: local
ansible.builtin.file:
path: ~/.kube
state: directory
mode: "0700"

- name: Create local kubernetes config
delegate_to: kvm_host_local
connection: local
ansible.builtin.copy:
content: "{{ slurpfile.content | b64decode }}"
dest: ~/.kube/config
mode: "0700"

- name: Copy kubeconfig to nodes
block:

- name: Include task node_kubeconfig
with_items: "{{ nodes }}"
ansible.builtin.include_tasks:
file: node_kubeconfig.yaml
24 changes: 3 additions & 21 deletions roles/cluster_control_plane_init/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,9 @@
--kubernetes-version=v"{{ kubernetes_minor_version }}"
--pod-network-cidr=10.244.0.0/16

- name: Fetch cluster config
become: true
register: slurpfile
ansible.builtin.slurp:
src: /etc/kubernetes/admin.conf

- name: Ensure .kube directory exists
delegate_to: kvm_host_local
connection: local
ansible.builtin.file:
path: ~/.kube
state: directory
mode: "0700"

- name: Create local kubernetes config
delegate_to: kvm_host_local
connection: local
ansible.builtin.copy:
content: "{{ slurpfile.content | b64decode }}"
dest: ~/.kube/config
mode: "0700"
- name: Include task kubeconfig
ansible.builtin.include_tasks:
file: kubeconfig.yaml

- name: Apply CNI plugin
delegate_to: kvm_host_local
Expand Down
33 changes: 33 additions & 0 deletions roles/cluster_control_plane_init/tasks/node_kubeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Ensure .kube directory exists
delegate_to: "{{ item.name }}"
ansible.builtin.file:
path: ~/.kube
state: directory
mode: "0700"

- name: Create local kubernetes config
delegate_to: "{{ item.name }}"
ansible.builtin.copy:
content: "{{ slurpfile.content | b64decode }}"
dest: ~/.kube/config
mode: "0700"

- name: Set up kubectl autocompletion
ansible.builtin.lineinfile:
dest: ~/.bashrc
line: "source <(kubectl completion bash)"
state: present

- name: Set up k alias
ansible.builtin.lineinfile:
dest: ~/.bashrc
line: "alias k=kubectl"
state: present

- name: Set up k alias autocompletion
ansible.builtin.lineinfile:
dest: ~/.bashrc
insertafter: "alias k=kubectl"
line: "complete -o default -F __start_kubectl k"
state: present
16 changes: 14 additions & 2 deletions roles/kvm_host_set_up/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,17 @@
ansible.builtin.lineinfile:
path: ~/.bashrc
state: present
regexp: "^source <(kubectl completion bash)"
line: source <(kubectl completion bash)
line: "source <(kubectl completion bash)"

- name: Set up k alias
ansible.builtin.lineinfile:
dest: ~/.bashrc
line: "alias k=kubectl"
state: present

- name: Set up k alias autocompletion
ansible.builtin.lineinfile:
dest: ~/.bashrc
insertafter: "alias k=kubectl"
line: "complete -o default -F __start_kubectl k"
state: present

0 comments on commit 1d41754

Please sign in to comment.