Skip to content

Commit

Permalink
Use FQCN for builtin actions
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Brookman <[email protected]>
  • Loading branch information
bcbrookman authored and dereknola committed Nov 7, 2023
1 parent 103aca8 commit 538ca26
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
6 changes: 3 additions & 3 deletions roles/download/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: Download k3s binary x64
get_url:
ansible.builtin.get_url:
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
timeout: 120
Expand All @@ -12,7 +12,7 @@
when: ansible_facts.architecture == "x86_64"

- name: Download k3s binary arm64
get_url:
ansible.builtin.get_url:
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
timeout: 120
Expand All @@ -26,7 +26,7 @@
ansible_facts.architecture is search("aarch64")

- name: Download k3s binary armhf
get_url:
ansible.builtin.get_url:
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
timeout: 120
Expand Down
46 changes: 23 additions & 23 deletions roles/k3s/master/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
- name: Clean previous runs of k3s-init
systemd:
ansible.builtin.systemd:
name: k3s-init
state: stopped
failed_when: false

- name: Clean previous runs of k3s-init
command: systemctl reset-failed k3s-init
ansible.builtin.command: systemctl reset-failed k3s-init
failed_when: false
changed_when: false
args:
warn: false # The ansible systemd module does not support reset-failed

- name: Init cluster inside the transient k3s-init service
command:
ansible.builtin.command:
cmd: "systemd-run -p RestartSec=2 \
-p Restart=on-failure \
--unit=k3s-init \
Expand All @@ -25,7 +25,7 @@
- name: Verification
block:
- name: Verify that all nodes actually joined (check k3s-init.service if this fails)
command:
ansible.builtin.command:
cmd: k3s kubectl get nodes -l "node-role.kubernetes.io/master=true" -o=jsonpath="{.items[*].metadata.name}"
register: nodes
until: nodes.rc == 0 and (nodes.stdout.split() | length) == (groups['master'] | length)
Expand All @@ -34,85 +34,85 @@
changed_when: false
always:
- name: Kill the temporary service used for initialization
systemd:
ansible.builtin.systemd:
name: k3s-init
state: stopped
failed_when: false

- name: Copy K3s service file
register: k3s_service
template:
ansible.builtin.template:
src: "k3s.service.j2"
dest: "{{ systemd_dir }}/k3s.service"
owner: root
group: root
mode: 0644

- name: Enable and check K3s service
systemd:
ansible.builtin.systemd:
name: k3s
daemon_reload: yes
state: restarted
enabled: yes

- name: Wait for node-token
wait_for:
path: "{{ k3s_server_location }}/server/node-token"
ansible.builtin.wait_for:
path: {{ k3s_server_location }}/server/node-token

Check failure on line 60 in roles/k3s/master/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

60:13 [braces] too many spaces inside braces

Check failure on line 60 in roles/k3s/master/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

60:33 [braces] too many spaces inside braces

- name: Register node-token file access mode
stat:
path: "{{ k3s_server_location }}/server/node-token"
ansible.builtin.stat:
path: {{ k3s_server_location }}/server

Check failure on line 64 in roles/k3s/master/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

64:13 [braces] too many spaces inside braces

Check failure on line 64 in roles/k3s/master/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

64:33 [braces] too many spaces inside braces
register: p

- name: Change file access node-token
file:
path: "{{ k3s_server_location }}/server/node-token"
ansible.builtin.file:
path: {{ k3s_server_location }}/server

Check failure on line 69 in roles/k3s/master/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

69:13 [braces] too many spaces inside braces

Check failure on line 69 in roles/k3s/master/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

69:33 [braces] too many spaces inside braces
mode: "g+rx,o+rx"

- name: Read node-token from master
slurp:
path: "{{ k3s_server_location }}/server/node-token"
ansible.builtin.slurp:
src: {{ k3s_server_location }}/server/node-token
register: node_token

- name: Store Master node-token
set_fact:
ansible.builtin.set_fact:
token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}"

- name: Restore node-token file access
file:
path: "{{ k3s_server_location }}/server/node-token"
ansible.builtin.file:
path: {{ k3s_server_location }}/server
mode: "{{ p.stat.mode }}"

- name: Create directory .kube
file:
ansible.builtin.file:
path: ~{{ ansible_user }}/.kube
state: directory
owner: "{{ ansible_user }}"
mode: "u=rwx,g=rx,o="

- name: Copy config file to user home directory
copy:
ansible.builtin.copy:
src: /etc/rancher/k3s/k3s.yaml
dest: ~{{ ansible_user }}/.kube/config
remote_src: yes
owner: "{{ ansible_user }}"
mode: "u=rw,g=,o="

- name: Configure kubectl cluster to https://{{ apiserver_endpoint }}:{{ apiserver_port | default(6443) }}
command: >-
ansible.builtin.command: >-
/usr/local/bin/k3s kubectl config set-cluster default
--server=https://{{ apiserver_endpoint }}:{{ apiserver_port | default(6443) }}
--kubeconfig ~{{ ansible_user }}/.kube/config
changed_when: true

- name: Create kubectl symlink
file:
ansible.builtin.file:
src: /usr/local/bin/k3s
dest: /usr/local/bin/kubectl
state: link

- name: Create crictl symlink
file:
ansible.builtin.file:
src: /usr/local/bin/k3s
dest: /usr/local/bin/crictl
state: link
4 changes: 2 additions & 2 deletions roles/k3s/node/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---

- name: Copy K3s service file
template:
ansible.builtin.template:
src: "k3s.service.j2"
dest: "{{ systemd_dir }}/k3s-node.service"
owner: root
group: root
mode: 0755

- name: Enable and check K3s service
systemd:
ansible.builtin.systemd:
name: k3s-node
daemon_reload: yes
state: restarted
Expand Down
4 changes: 2 additions & 2 deletions roles/prereq/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
when: ansible_all_ipv6_addresses

- name: Add br_netfilter to /etc/modules-load.d/
copy:
ansible.builtin.copy:
content: "br_netfilter"
dest: /etc/modules-load.d/br_netfilter.conf
mode: "u=rw,g=,o="
Expand All @@ -44,7 +44,7 @@
- net.bridge.bridge-nf-call-ip6tables

- 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'
regexp: "Defaults(\\s)*secure_path(\\s)*="
state: present
Expand Down
2 changes: 1 addition & 1 deletion roles/raspberrypi/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
- name: reboot
reboot:
ansible.builtin.reboot:
10 changes: 5 additions & 5 deletions roles/raspberrypi/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
- 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
failed_when: false
changed_when: false

- 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
failed_when: false
changed_when: false

- name: Set raspberry_pi fact to true
set_fact:
ansible.builtin.set_fact:
raspberry_pi: true
when:
grep_cpuinfo_raspberrypi.rc == 0 or grep_device_tree_model_raspberrypi.rc == 0

- name: Set detected_distribution to Raspbian
set_fact:
ansible.builtin.set_fact:
detected_distribution: Raspbian
when: >
raspberry_pi|default(false) and
Expand All @@ -34,7 +34,7 @@
ansible_facts.lsb.description|default("") is match("Debian") )
- name: Set detected_distribution_major_version
set_fact:
ansible.builtin.set_fact:
detected_distribution_major_version: "{{ ansible_facts.lsb.major_release }}"
when: >

Check failure on line 39 in roles/raspberrypi/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

39:10 [trailing-spaces] trailing spaces
( detected_distribution | default("") == "Raspbian" or
Expand Down
2 changes: 1 addition & 1 deletion roles/raspberrypi/tasks/prereq/CentOS.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Enable cgroup via boot commandline if not already enabled for Centos
lineinfile:
ansible.builtin.lineinfile:
path: /boot/cmdline.txt
backrefs: yes
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'
Expand Down
4 changes: 2 additions & 2 deletions roles/raspberrypi/tasks/prereq/Raspbian.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
- name: Activating cgroup support
lineinfile:
ansible.builtin.lineinfile:
path: /boot/cmdline.txt
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'
line: '\1 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory'
backrefs: true
notify: reboot

- name: Flush iptables before changing to iptables-legacy
iptables:
ansible.builtin.iptables:
flush: true
changed_when: false # iptables flush always returns changed

Expand Down
2 changes: 1 addition & 1 deletion roles/raspberrypi/tasks/prereq/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- 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
backrefs: yes
regexp: '^((?!.*\bcgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory\b).*)$'
Expand Down
8 changes: 4 additions & 4 deletions roles/reset/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Disable services
systemd:
ansible.builtin.systemd:
name: "{{ item }}"
state: stopped
enabled: no
Expand All @@ -12,7 +12,7 @@

- name: pkill -9 -f "k3s/data/[^/]+/bin/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"
failed_when: false

Expand All @@ -27,7 +27,7 @@
loop_var: mounted_fs

- name: Remove service files, binaries and data
file:
ansible.builtin.file:
name: "{{ item }}"
state: absent
with_items:
Expand All @@ -39,5 +39,5 @@
- /var/lib/rancher/k3s

- name: daemon_reload
systemd:
ansible.builtin.systemd:
daemon_reload: yes
2 changes: 1 addition & 1 deletion roles/reset/tasks/umount_with_children.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- 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
args:
executable: /bin/bash
Expand Down

0 comments on commit 538ca26

Please sign in to comment.