Comply with ansible-lint

Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
Derek Nola
2023-11-07 13:35:08 -08:00
parent 5b17c77e71
commit 1031ea3ce2
15 changed files with 74 additions and 67 deletions

2
.gitignore vendored
View File

@@ -0,0 +1,2 @@
.vscode
.vagrant

View File

@@ -1,6 +1,7 @@
--- ---
- hosts: k3s_cluster - name: Reset K3s cluster
hosts: k3s_cluster
gather_facts: yes gather_facts: yes
become: yes become: yes
roles: roles:

View File

@@ -1,7 +1,7 @@
--- ---
- name: Download k3s binary x64 - name: Download k3s binary x64
get_url: ansible.builtin.get_url:
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt
timeout: 120 timeout: 120
@@ -12,7 +12,7 @@
when: ansible_facts.architecture == "x86_64" when: ansible_facts.architecture == "x86_64"
- name: Download k3s binary arm64 - name: Download k3s binary arm64
get_url: ansible.builtin.get_url:
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-arm64 url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-arm64
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm64.txt checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm64.txt
timeout: 120 timeout: 120
@@ -26,7 +26,7 @@
ansible_facts.architecture is search("aarch64") ansible_facts.architecture is search("aarch64")
- name: Download k3s binary armhf - name: Download k3s binary armhf
get_url: ansible.builtin.get_url:
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-armhf url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-armhf
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm.txt checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm.txt
timeout: 120 timeout: 120

View File

@@ -2,7 +2,7 @@
- name: Copy K3s service file - name: Copy K3s service file
register: k3s_service register: k3s_service
template: ansible.builtin.template:
src: "k3s.service.j2" src: "k3s.service.j2"
dest: "{{ systemd_dir }}/k3s.service" dest: "{{ systemd_dir }}/k3s.service"
owner: root owner: root
@@ -10,49 +10,49 @@
mode: 0644 mode: 0644
- name: Enable and check K3s service - name: Enable and check K3s service
systemd: ansible.builtin.systemd:
name: k3s name: k3s
daemon_reload: yes daemon_reload: yes
state: restarted state: restarted
enabled: yes enabled: yes
- name: Wait for node-token - name: Wait for node-token
wait_for: ansible.builtin.wait_for:
path: "{{ k3s_server_location }}/server/node-token" path: "{{ k3s_server_location }}/server/node-token"
- name: Register node-token file access mode - name: Register node-token file access mode
stat: ansible.builtin.stat:
path: "{{ k3s_server_location }}/server/node-token" path: "{{ k3s_server_location }}/server/node-token"
register: p register: p
- name: Change file access node-token - name: Change file access node-token
file: ansible.builtin.file:
path: "{{ k3s_server_location }}/server/node-token" path: "{{ k3s_server_location }}/server/node-token"
mode: "g+rx,o+rx" mode: "g+rx,o+rx"
- name: Read node-token from master - name: Read node-token from master
slurp: ansible.builtin.slurp:
path: "{{ k3s_server_location }}/server/node-token" path: "{{ k3s_server_location }}/server/node-token"
register: node_token register: node_token
- name: Store Master node-token - name: Store Master node-token
set_fact: ansible.builtin.set_fact:
token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}" token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}"
- name: Restore node-token file access - name: Restore node-token file access
file: ansible.builtin.file:
path: "{{ k3s_server_location }}/server/node-token" path: "{{ k3s_server_location }}/server/node-token"
mode: "{{ p.stat.mode }}" mode: "{{ p.stat.mode }}"
- name: Create directory .kube - name: Create directory .kube
file: ansible.builtin.file:
path: ~{{ ansible_user }}/.kube path: ~{{ ansible_user }}/.kube
state: directory state: directory
owner: "{{ ansible_user }}" owner: "{{ ansible_user }}"
mode: "u=rwx,g=rx,o=" mode: "u=rwx,g=rx,o="
- name: Copy config file to user home directory - name: Copy config file to user home directory
copy: ansible.builtin.copy:
src: /etc/rancher/k3s/k3s.yaml src: /etc/rancher/k3s/k3s.yaml
dest: ~{{ ansible_user }}/.kube/config dest: ~{{ ansible_user }}/.kube/config
remote_src: yes remote_src: yes
@@ -60,20 +60,20 @@
mode: "u=rw,g=,o=" mode: "u=rw,g=,o="
- name: Replace https://localhost:6443 by https://master-ip:6443 - name: Replace https://localhost:6443 by https://master-ip:6443
command: >- ansible.builtin.command: >-
/usr/local/bin/k3s kubectl config set-cluster default /usr/local/bin/k3s kubectl config set-cluster default
--server=https://{{ master_ip }}:6443 --server=https://{{ master_ip }}:6443
--kubeconfig ~{{ ansible_user }}/.kube/config --kubeconfig ~{{ ansible_user }}/.kube/config
changed_when: true changed_when: true
- name: Create kubectl symlink - name: Create kubectl symlink
file: ansible.builtin.file:
src: /usr/local/bin/k3s src: /usr/local/bin/k3s
dest: /usr/local/bin/kubectl dest: /usr/local/bin/kubectl
state: link state: link
- name: Create crictl symlink - name: Create crictl symlink
file: ansible.builtin.file:
src: /usr/local/bin/k3s src: /usr/local/bin/k3s
dest: /usr/local/bin/crictl dest: /usr/local/bin/crictl
state: link state: link

View File

@@ -1,7 +1,7 @@
--- ---
- name: Copy K3s service file - name: Copy K3s service file
template: ansible.builtin.template:
src: "k3s.service.j2" src: "k3s.service.j2"
dest: "{{ systemd_dir }}/k3s-node.service" dest: "{{ systemd_dir }}/k3s-node.service"
owner: root owner: root
@@ -9,7 +9,7 @@
mode: 0755 mode: 0755
- name: Enable and check K3s service - name: Enable and check K3s service
systemd: ansible.builtin.systemd:
name: k3s-node name: k3s-node
daemon_reload: yes daemon_reload: yes
state: restarted state: restarted

View File

@@ -1,18 +1,18 @@
--- ---
- name: Set SELinux to disabled state - name: Set SELinux to disabled state
selinux: ansible.posix.selinux:
state: disabled state: disabled
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux','RedHat'] when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux','RedHat']
- name: Enable IPv4 forwarding - name: Enable IPv4 forwarding
sysctl: ansible.posix.sysctl:
name: net.ipv4.ip_forward name: net.ipv4.ip_forward
value: "1" value: "1"
state: present state: present
reload: yes reload: yes
- name: Enable IPv6 forwarding - name: Enable IPv6 forwarding
sysctl: ansible.posix.sysctl:
name: net.ipv6.conf.all.forwarding name: net.ipv6.conf.all.forwarding
value: "1" value: "1"
state: present state: present
@@ -20,20 +20,20 @@
when: ansible_all_ipv6_addresses when: ansible_all_ipv6_addresses
- name: Add br_netfilter to /etc/modules-load.d/ - name: Add br_netfilter to /etc/modules-load.d/
copy: ansible.builtin.copy:
content: "br_netfilter" content: "br_netfilter"
dest: /etc/modules-load.d/br_netfilter.conf dest: /etc/modules-load.d/br_netfilter.conf
mode: "u=rw,g=,o=" mode: "u=rw,g=,o="
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux','RedHat'] when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux','RedHat']
- name: Load br_netfilter - name: Load br_netfilter
modprobe: community.general.modprobe:
name: br_netfilter name: br_netfilter
state: present state: present
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux','RedHat'] when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux','RedHat']
- name: Set bridge-nf-call-iptables (just to be sure) - name: Set bridge-nf-call-iptables (just to be sure)
sysctl: ansible.posix.sysctl:
name: "{{ item }}" name: "{{ item }}"
value: "1" value: "1"
state: present state: present
@@ -44,7 +44,7 @@
- net.bridge.bridge-nf-call-ip6tables - net.bridge.bridge-nf-call-ip6tables
- name: Add /usr/local/bin to sudo secure_path - name: Add /usr/local/bin to sudo secure_path
lineinfile: ansible.builtin.lineinfile:
line: 'Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin' line: 'Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin'
regexp: "Defaults(\\s)*secure_path(\\s)*=" regexp: "Defaults(\\s)*secure_path(\\s)*="
state: present state: present

View File

@@ -1,3 +1,3 @@
--- ---
- name: reboot - name: Reboot
reboot: ansible.builtin.reboot:

View File

@@ -1,24 +1,24 @@
--- ---
- name: Test for raspberry pi /proc/cpuinfo - name: Test for raspberry pi /proc/cpuinfo
command: grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo ansible.builtin.command: grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo
register: grep_cpuinfo_raspberrypi register: grep_cpuinfo_raspberrypi
failed_when: false failed_when: false
changed_when: false changed_when: false
- name: Test for raspberry pi /proc/device-tree/model - name: Test for raspberry pi /proc/device-tree/model
command: grep -E "Raspberry Pi" /proc/device-tree/model ansible.builtin.command: grep -E "Raspberry Pi" /proc/device-tree/model
register: grep_device_tree_model_raspberrypi register: grep_device_tree_model_raspberrypi
failed_when: false failed_when: false
changed_when: false changed_when: false
- name: Set raspberry_pi fact to true - name: Set raspberry_pi fact to true
set_fact: ansible.builtin.set_fact:
raspberry_pi: true raspberry_pi: true
when: when:
grep_cpuinfo_raspberrypi.rc == 0 or grep_device_tree_model_raspberrypi.rc == 0 grep_cpuinfo_raspberrypi.rc == 0 or grep_device_tree_model_raspberrypi.rc == 0
- name: Set detected_distribution to Raspbian - name: Set detected_distribution to Raspbian
set_fact: ansible.builtin.set_fact:
detected_distribution: Raspbian detected_distribution: Raspbian
when: > when: >
raspberry_pi|default(false) and raspberry_pi|default(false) and
@@ -26,7 +26,7 @@
ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*") ) ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*") )
- name: Set detected_distribution to Debian - name: Set detected_distribution to Debian
set_fact: ansible.builtin.set_fact:
detected_distribution: Debian detected_distribution: Debian
when: > when: >
raspberry_pi|default(false) and raspberry_pi|default(false) and
@@ -34,14 +34,14 @@
ansible_facts.lsb.description|default("") is match("Debian") ) ansible_facts.lsb.description|default("") is match("Debian") )
- name: Set detected_distribution_major_version - name: Set detected_distribution_major_version
set_fact: ansible.builtin.set_fact:
detected_distribution_major_version: "{{ ansible_facts.lsb.major_release }}" detected_distribution_major_version: "{{ ansible_facts.lsb.major_release }}"
when: > when: >
( detected_distribution | default("") == "Raspbian" or ( detected_distribution | default("") == "Raspbian" or
detected_distribution | default("") == "Debian" ) detected_distribution | default("") == "Debian" )
- name: execute OS related tasks on the Raspberry Pi - name: Execute OS related tasks on the Raspberry Pi
include_tasks: "{{ item }}" ansible.builtin.include_tasks: "{{ item }}"
with_first_found: with_first_found:
- "prereq/{{ detected_distribution }}-{{ detected_distribution_major_version }}.yml" - "prereq/{{ detected_distribution }}-{{ detected_distribution_major_version }}.yml"
- "prereq/{{ detected_distribution }}.yml" - "prereq/{{ detected_distribution }}.yml"

View File

@@ -1,6 +1,6 @@
--- ---
- name: Enable cgroup via boot commandline if not already enabled for Centos - name: Enable cgroup via boot commandline if not already enabled for Centos
lineinfile: ansible.builtin.lineinfile:
path: /boot/cmdline.txt path: /boot/cmdline.txt
backrefs: yes backrefs: yes
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'

View File

@@ -1,11 +1,11 @@
--- ---
- name: Check if /boot/firmware/cmdline.txt exists - name: Check if /boot/firmware/cmdline.txt exists
stat: ansible.builtin.stat:
path: /boot/firmware/cmdline.txt path: /boot/firmware/cmdline.txt
register: boot_firmware_cmdline_txt register: boot_firmware_cmdline_txt
- name: Activating cgroup support - name: Activating cgroup support
lineinfile: ansible.builtin.lineinfile:
path: "{{ (boot_firmware_cmdline_txt.stat.exists) | ternary('/boot/firmware/cmdline.txt', '/boot/cmdline.txt') }}" path: "{{ (boot_firmware_cmdline_txt.stat.exists) | ternary('/boot/firmware/cmdline.txt', '/boot/cmdline.txt') }}"
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'
line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory'
@@ -13,22 +13,22 @@
notify: reboot notify: reboot
- name: Install iptables - name: Install iptables
apt: ansible.builtin.apt:
name: iptables name: iptables
- name: Flush iptables before changing to iptables-legacy - name: Flush iptables before changing to iptables-legacy
iptables: ansible.builtin.iptables:
flush: true flush: true
changed_when: false # iptables flush always returns changed changed_when: false # iptables flush always returns changed
- name: Changing to iptables-legacy - name: Changing to iptables-legacy
alternatives: community.general.alternatives:
path: /usr/sbin/iptables-legacy path: /usr/sbin/iptables-legacy
name: iptables name: iptables
register: ip4_legacy register: ip4_legacy
- name: Changing to ip6tables-legacy - name: Changing to ip6tables-legacy
alternatives: community.general.alternatives:
path: /usr/sbin/ip6tables-legacy path: /usr/sbin/ip6tables-legacy
name: ip6tables name: ip6tables
register: ip6_legacy register: ip6_legacy

View File

@@ -1,6 +1,6 @@
--- ---
- name: Activating cgroup support - name: Activating cgroup support
lineinfile: ansible.builtin.lineinfile:
path: /boot/cmdline.txt path: /boot/cmdline.txt
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'
line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory'
@@ -8,18 +8,18 @@
notify: reboot notify: reboot
- name: Flush iptables before changing to iptables-legacy - name: Flush iptables before changing to iptables-legacy
iptables: ansible.builtin.iptables:
flush: true flush: true
changed_when: false # iptables flush always returns changed changed_when: false # iptables flush always returns changed
- name: Changing to iptables-legacy - name: Changing to iptables-legacy
alternatives: community.general.alternatives:
path: /usr/sbin/iptables-legacy path: /usr/sbin/iptables-legacy
name: iptables name: iptables
register: ip4_legacy register: ip4_legacy
- name: Changing to ip6tables-legacy - name: Changing to ip6tables-legacy
alternatives: community.general.alternatives:
path: /usr/sbin/ip6tables-legacy path: /usr/sbin/ip6tables-legacy
name: ip6tables name: ip6tables
register: ip6_legacy register: ip6_legacy

View File

@@ -1,15 +1,16 @@
--- ---
- name: Enable cgroup via boot commandline if not already enabled for Ubuntu on a Raspberry Pi - name: Enable cgroup via boot commandline if not already enabled for Ubuntu on a Raspberry Pi
lineinfile: ansible.builtin.lineinfile:
path: /boot/firmware/cmdline.txt path: /boot/firmware/cmdline.txt
backrefs: yes backrefs: yes
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$' regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'
line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory' line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory'
notify: reboot notify: reboot
- name: Install Ubuntu Raspi Extra Packages - name: Install Ubuntu Raspi Extra Packages
apt: ansible.builtin.apt:
name: # Fixes issues in newer Ubuntu where VXLan isn't setup right.
- linux-modules-extra-raspi #Fixes issues in newer Ubuntu where VXLan isn't setup right. See: https://github.com/k3s-io/k3s/issues/4234 # See: https://github.com/k3s-io/k3s/issues/4234
name: linux-modules-extra-raspi
update_cache: yes update_cache: yes
state: present state: present
when: "ansible_distribution_version is version('20.10', '>=')" when: "ansible_distribution_version is version('20.10', '>=')"

View File

@@ -1,6 +1,6 @@
--- ---
- name: Disable services - name: Disable services
systemd: ansible.builtin.systemd:
name: "{{ item }}" name: "{{ item }}"
state: stopped state: stopped
enabled: no enabled: no
@@ -9,14 +9,14 @@
- k3s - k3s
- k3s-node - k3s-node
- name: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc" - name: Pkill k3s container runtimes"
register: pkill_containerd_shim_runc register: pkill_containerd_shim_runc
command: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc" ansible.builtin.command: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc"
changed_when: "pkill_containerd_shim_runc.rc == 0" changed_when: "pkill_containerd_shim_runc.rc == 0"
failed_when: false failed_when: false
- name: Umount k3s filesystems - name: Umount k3s filesystems
include_tasks: umount_with_children.yml ansible.builtin.include_tasks: umount_with_children.yml
with_items: with_items:
- /run/k3s - /run/k3s
- /var/lib/kubelet - /var/lib/kubelet
@@ -26,7 +26,7 @@
loop_var: mounted_fs loop_var: mounted_fs
- name: Remove service files, binaries and data - name: Remove service files, binaries and data
file: ansible.builtin.file:
name: "{{ item }}" name: "{{ item }}"
state: absent state: absent
with_items: with_items:
@@ -37,6 +37,6 @@
- /var/lib/kubelet - /var/lib/kubelet
- /var/lib/rancher/k3s - /var/lib/rancher/k3s
- name: daemon_reload - name: Daemon_reload
systemd: ansible.builtin.systemd:
daemon_reload: yes daemon_reload: yes

View File

@@ -1,6 +1,6 @@
--- ---
- name: Get the list of mounted filesystems - name: Get the list of mounted filesystems
shell: set -o pipefail && cat /proc/mounts | awk '{ print $2}' | grep -E "^{{ mounted_fs }}" ansible.builtin.shell: set -o pipefail && cat /proc/mounts | awk '{ print $2}' | grep -E "^{{ mounted_fs }}"
register: get_mounted_filesystems register: get_mounted_filesystems
args: args:
executable: /bin/bash executable: /bin/bash
@@ -9,7 +9,7 @@
check_mode: false check_mode: false
- name: Umount filesystem - name: Umount filesystem
mount: ansible.posix.mount:
path: "{{ item }}" path: "{{ item }}"
state: unmounted state: unmounted
with_items: with_items:

View File

@@ -1,6 +1,7 @@
--- ---
- hosts: k3s_cluster - name: "Setup K3s Cluster"
hosts: k3s_cluster
gather_facts: yes gather_facts: yes
become: yes become: yes
roles: roles:
@@ -8,12 +9,14 @@
- role: download - role: download
- role: raspberrypi - role: raspberrypi
- hosts: master - name: "Server Setup"
hosts: master
become: yes become: yes
roles: roles:
- role: k3s/master - role: k3s/master # noqa: role-name[path]
- hosts: node - name: "Agent Setup"
hosts: node
become: yes become: yes
roles: roles:
- role: k3s/node - role: k3s/node # noqa: role-name[path]