Skip to content

Commit

Permalink
fix(k8s-node): lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshnayak305 committed Dec 6, 2024
1 parent bf84968 commit 00d848c
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
exclude_paths:
- .github
- .vscode
- ci
- ci
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ansible.python.interpreterPath": "/usr/bin/python"
"ansible.python.interpreterPath": "/bin/python"
}
8 changes: 8 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ extends: default

rules:
line-length: disable
comments-indentation: false
comments:
min-spaces-from-content: 1
braces:
max-spaces-inside: 1
octal-values:
forbid-explicit-octal: true
forbid-implicit-octal: true

ignore: |
.github
Expand Down
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# Collections must specify a minimum required ansible version to upload
# to galaxy
requires_ansible: '>=2.9.10'
requires_ansible: ">=2.18.0"
5 changes: 1 addition & 4 deletions roles/k8s_node/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
---
# defaults file for k8s_node
ssh_id_rsa_pubs: []
allow_kube_upgrade: false
# tmpdir
tmpdir: /tmp
k8s_node_ssh_id_rsa_pubs: []
4 changes: 2 additions & 2 deletions roles/k8s_node/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
# handlers file for k8s_node
- name: restart containerd
- name: Restart Containerd
become: true
become_user: root
ansible.builtin.service:
name: "containerd"
state: "restarted"
enabled: true

- name: restart kubelet
- name: Restart Kubelet
become: true
ansible.builtin.service:
name: kubelet
Expand Down
5 changes: 2 additions & 3 deletions roles/k8s_node/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ galaxy_info:
company: "-"
issue_tracker_url: https://github.com/hiteshnayak305/ansible-homelab/issues
license: license (MIT)
min_ansible_version: "2.1"
min_ansible_version: "2.18.0"
platforms:
- name: Ubuntu
versions:
- all
galaxy_tags:
- K8s
- Kubernetes Node
- kubernetes
dependencies: []
12 changes: 6 additions & 6 deletions roles/k8s_node/tasks/01_kube_sudoer.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- name: Ensure group {{ kubernetes_user }} exists
- name: Ensure group exists {{ kubernetes_user }}
ansible.builtin.group:
name: "{{ kubernetes_user }}"
state: present

- name: create the {{ kubernetes_user }} user account
- name: Create the user account {{ kubernetes_user }}
ansible.builtin.user:
name: "{{ kubernetes_user }}"
append: true
Expand All @@ -14,15 +14,15 @@
groups:
- "{{ kubernetes_user }}"

- name: allow {{ kubernetes_user }} to use sudo without needing a password
- name: Allow to use sudo without needing a password user {{ kubernetes_user }}
ansible.builtin.lineinfile:
dest: /etc/sudoers
line: "{{ kubernetes_user }} ALL=(ALL) NOPASSWD: ALL"
validate: "visudo -cf %s"

- name: set up authorized keys for the {{ kubernetes_user }} user
ansible.builtin.authorized_key:
- name: Set up authorized keys for the user {{ kubernetes_user }}
ansible.posix.authorized_key:
user: "{{ kubernetes_user }}"
state: present
key: "{{ item }}"
with_file: "{{ ssh_id_rsa_pubs }}"
with_file: "{{ k8s_node_ssh_id_rsa_pubs }}"
5 changes: 3 additions & 2 deletions roles/k8s_node/tasks/02_kube_nfs_mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
state: directory
owner: nobody
group: nogroup
mode: "0777"
with_items:
- "/home/{{ kubernetes_user }}/nfs/ssd_0"
- "/home/{{ kubernetes_user }}/nfs/hdd_0"

- name: Mount NFS volume ssd_0
ansible.builtin.mount:
ansible.posix.mount:
src: "{{ nfs_server }}:/mnt/nfs/ssd_0"
path: "/home/{{ kubernetes_user }}/nfs/ssd_0"
opts: rw,sync,hard
Expand All @@ -19,7 +20,7 @@
when: nfs_server is defined

- name: Mount NFS volume hdd_0
ansible.builtin.mount:
ansible.posix.mount:
src: "{{ nfs_server }}:/mnt/nfs/hdd_0"
path: "/home/{{ kubernetes_user }}/nfs/hdd_0"
opts: rw,sync,hard
Expand Down
2 changes: 1 addition & 1 deletion roles/k8s_node/tasks/03_kube_modprobe.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Enable modprobe 'overlay'
ansible.builtin.modprobe:
community.general.modprobe:
name: "{{ item }}"
state: present
with_items:
Expand Down
3 changes: 2 additions & 1 deletion roles/k8s_node/tasks/04_kube_disable_swap.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Remove swapfile from /etc/fstab
ansible.builtin.mount:
ansible.posix.mount:
name: "{{ item }}"
fstype: swap
state: absent
Expand All @@ -11,3 +11,4 @@
- name: Disable swap
ansible.builtin.command: swapoff -a
when: ansible_swaptotal_mb > 0
changed_when: ansible_swaptotal_mb > 0
6 changes: 5 additions & 1 deletion roles/k8s_node/tasks/05_kube_configure_sysctl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
ansible.builtin.file:
path: /etc/modules-load.d
state: directory
mode: "0764"

- name: Copy the kube modules
ansible.builtin.copy:
src: "files/etc/modules-load.d/k8s.conf"
dest: "/etc/modules-load.d/k8s.conf"
mode: "0644"

- name: Make sure the folder exists => /etc/sysctl.d
ansible.builtin.file:
path: /etc/sysctl.d
state: directory
mode: "0764"

- name: Copy the kube sysctl conf
ansible.builtin.copy:
src: "files/etc/sysctl.d/k8s.conf"
dest: "/etc/sysctl.d/k8s.conf"
mode: "0644"

- name: set ipv4 forward to 1
- name: Set ipv4 forward to 1
ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: "1"
Expand Down
15 changes: 9 additions & 6 deletions roles/k8s_node/tasks/06_kube_configure_containerd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ansible.builtin.file:
path: /etc/containerd
state: directory
mode: "0764"

- name: Get defaults from containerd.
ansible.builtin.command: containerd config default
Expand All @@ -11,13 +12,14 @@

- name: Prepare containerd/config.toml from default config
ansible.builtin.copy:
dest: "{{ tmpdir }}/containerd_config.toml"
dest: "{{ k8s_node_tmpdir }}/containerd_config.toml"
content: "{{ containerd_config_default.stdout }}"
mode: "0666"
changed_when: false

- name: Ensure Systemd Cgroup is used
ansible.builtin.lineinfile:
path: "{{ tmpdir }}/containerd_config.toml"
path: "{{ k8s_node_tmpdir }}/containerd_config.toml"
regexp: "^ SystemdCgroup ="
line: " SystemdCgroup = true"
backrefs: true
Expand All @@ -26,7 +28,7 @@

- name: Ensure sandbox image version
ansible.builtin.lineinfile:
path: "{{ tmpdir }}/containerd_config.toml"
path: "{{ k8s_node_tmpdir }}/containerd_config.toml"
regexp: "^ sandbox_image ="
line: ' sandbox_image = "registry.k8s.io/pause:3.9"'
backrefs: true
Expand All @@ -36,13 +38,14 @@
- name: Copy config.toml to /etc/containerd
ansible.builtin.copy:
remote_src: true
src: "{{ tmpdir }}/containerd_config.toml"
src: "{{ k8s_node_tmpdir }}/containerd_config.toml"
dest: /etc/containerd/config.toml
mode: "0644"
notify:
- restart containerd
- Restart Containerd

- name: Cleanup temporary file
ansible.builtin.file:
path: "{{ tmpdir }}/containerd_config.toml"
path: "{{ k8s_node_tmpdir }}/containerd_config.toml"
state: absent
changed_when: false
3 changes: 2 additions & 1 deletion roles/k8s_node/tasks/07_kube_configure_crictl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
ansible.builtin.copy:
src: "files/etc/crictl.yaml"
dest: "/etc/crictl.yaml"
mode: "0644"
notify:
- restart containerd
- Restart Containerd
5 changes: 3 additions & 2 deletions roles/k8s_node/tasks/08_kube_install_binaries.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Add an apt signing key for Kubernetes
ansible.builtin.shell: curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | gpg --dearmor --batch --yes -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
ansible.builtin.shell: set -o pipefail && curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | gpg --dearmor --batch --yes -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
changed_when: true

- name: Adding apt repository for Kubernetes
ansible.builtin.apt_repository:
Expand Down Expand Up @@ -28,4 +29,4 @@
- kubeadm
- kubectl
notify:
- restart kubelet
- Restart Kubelet
18 changes: 9 additions & 9 deletions roles/k8s_node/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
---
# tasks file for k8s_node
- name: execute role k8s_node
- name: Execute role k8s_node
become: true
become_user: root
block:
- name: Create User
include_tasks: 01_kube_sudoer.yml
ansible.builtin.include_tasks: 01_kube_sudoer.yml

- name: Mount shared NFS
include_tasks: 02_kube_nfs_mount.yml
ansible.builtin.include_tasks: 02_kube_nfs_mount.yml

- name: Enable modprobe Modules
include_tasks: 03_kube_modprobe.yml
ansible.builtin.include_tasks: 03_kube_modprobe.yml

- name: Disable Swap
include_tasks: 04_kube_disable_swap.yml
ansible.builtin.include_tasks: 04_kube_disable_swap.yml

- name: Configure Sysctl
include_tasks: 05_kube_configure_sysctl.yml
ansible.builtin.include_tasks: 05_kube_configure_sysctl.yml

- name: Configure Containerd
include_tasks: 06_kube_configure_containerd.yml
ansible.builtin.include_tasks: 06_kube_configure_containerd.yml

- name: Configure Crictl
include_tasks: 07_kube_configure_crictl.yml
ansible.builtin.include_tasks: 07_kube_configure_crictl.yml

- name: Install Kubernetes
include_tasks: 08_kube_install_binaries.yml
ansible.builtin.include_tasks: 08_kube_install_binaries.yml
2 changes: 2 additions & 0 deletions roles/k8s_node/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
---
# vars file for k8s_node
# k8s_node_tmpdir
k8s_node_tmpdir: /tmp

0 comments on commit 00d848c

Please sign in to comment.