Skip to content

Commit b77e004

Browse files
committed
Fix linting to bring back 'production' status for all non-server k3s roles
Signed-off-by: Derek Nola <[email protected]>
1 parent d397c5c commit b77e004

File tree

5 files changed

+63
-64
lines changed

5 files changed

+63
-64
lines changed

roles/airgap/tasks/main.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
delegate_to: localhost
1414
ansible.builtin.stat:
1515
path: "{{ airgap_dir + '/k3s-install.sh' }}"
16-
register: host_install_script
16+
register: airgap_host_install_script
1717

1818
- name: Download k3s install script
1919
become: false
2020
delegate_to: localhost
2121
# Workaround for https://github.com/ansible/ansible/issues/64016
22-
when: not host_install_script.stat.exists
22+
when: not airgap_host_install_script.stat.exists
2323
ansible.builtin.get_url:
2424
url: https://get.k3s.io/
2525
timeout: 120
@@ -34,11 +34,11 @@
3434
group: root
3535
mode: "0755"
3636

37-
- name: Determine architecture and set k3s_arch
37+
- name: Determine architecture and set airgap_k3s_arch
3838
ansible.builtin.set_fact:
39-
k3s_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'arm' if ansible_architecture == 'armv7l' else 'amd64' }}"
39+
airgap_k3s_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'arm' if ansible_architecture == 'armv7l' else 'amd64' }}"
4040

41-
- name: Distribute K3s binary {{ k3s_arch }}
41+
- name: Distribute K3s binary {{ airgap_k3s_arch }}
4242
ansible.builtin.copy:
4343
src: "{{ item }}"
4444
dest: /usr/local/bin/k3s
@@ -47,7 +47,7 @@
4747
mode: "0755"
4848
with_first_found:
4949
- files:
50-
- "{{ airgap_dir }}/k3s-{{ k3s_arch }}"
50+
- "{{ airgap_dir }}/k3s-{{ airgap_k3s_arch }}"
5151
- "{{ airgap_dir }}/k3s"
5252
# with_first_found always runs, even inside the when block
5353
# so we need to skip it if the file is not found
@@ -62,15 +62,15 @@
6262
mode: "0755"
6363
with_fileglob:
6464
- "{{ airgap_dir }}/k3s-selinux*.rpm"
65-
register: selinux_copy
65+
register: airgap_selinux_copy
6666
ignore_errors: true
6767

6868
- name: Install K3s SELinux RPM
6969
when:
7070
- ansible_os_family == 'RedHat'
71-
- selinux_copy.skipped is false
71+
- airgap_selinux_copy.skipped is false
7272
ansible.builtin.dnf:
73-
name: "{{ selinux_copy.results[0].dest }}"
73+
name: "{{ airgap_selinux_copy.results[0].dest }}"
7474
state: present
7575
disable_gpg_check: true
7676
disablerepo: "*"

roles/k3s_agent/tasks/main.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
22
- name: Get k3s installed version
33
ansible.builtin.command: k3s --version
4-
register: k3s_version_output
4+
register: k3s_agent_version_output
55
changed_when: false
66
ignore_errors: true
77

88
- name: Set k3s installed version
9-
when: not ansible_check_mode and k3s_version_output.rc == 0
9+
when: not ansible_check_mode and k3s_agent_version_output.rc == 0
1010
ansible.builtin.set_fact:
11-
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
11+
k3s_agent_installed_version: "{{ k3s_agent_version_output.stdout_lines[0].split(' ')[2] }}"
1212

1313
# If airgapped, all K3s artifacts are already on the node.
1414
# We should be downloading and installing the newer version only if we are in one of the following cases :
1515
# - we couldn't get k3s installed version in the first task of this role
1616
# - the installed version of K3s on the nodes is older than the requested version in ansible vars
1717
- name: Download artifact only if needed
18-
when: not ansible_check_mode and airgap_dir is undefined and ( k3s_version_output.rc != 0 or installed_k3s_version is version(k3s_version, '<') )
18+
when: not ansible_check_mode and airgap_dir is undefined and ( k3s_agent_version_output.rc != 0 or k3s_agent_installed_version is version(k3s_version, '<') )
1919
block:
2020
- name: Download K3s install script
2121
ansible.builtin.get_url:
@@ -50,13 +50,15 @@
5050
mode: "0755"
5151
state: directory
5252
- name: Copy config values
53+
# noqa var-naming[no-role-prefix]
5354
ansible.builtin.copy:
5455
content: "{{ agent_config_yaml }}"
5556
dest: "/etc/rancher/k3s/config.yaml"
5657
mode: "0644"
5758
register: _agent_config_result
5859

5960
- name: Get the token from the first server
61+
# noqa var-naming[no-role-prefix]
6062
ansible.builtin.set_fact:
6163
token: "{{ hostvars[groups[server_group][0]].token }}"
6264

roles/k3s_upgrade/tasks/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
# local control-plane instead of the remote host. Shell supports wildcards.
44
- name: Get k3s installed version
55
ansible.builtin.command: k3s --version
6-
register: k3s_version_output
6+
register: k3s_upgrade_version_output
77
changed_when: false
88
check_mode: false
99

1010
- name: Set k3s installed version
1111
ansible.builtin.set_fact:
12-
installed_k3s_version: "{{ k3s_version_output.stdout_lines[0].split(' ')[2] }}"
12+
k3s_upgrade_current_version: "{{ k3s_upgrade_version_output.stdout_lines[0].split(' ')[2] }}"
1313
check_mode: false
1414

1515
# We should be downloading and installing the newer version only if we are in the following case :
1616
# - the installed version of K3s on the nodes is older than the requested version in ansible vars
1717
- name: Update node only if needed
18-
when: installed_k3s_version is version(k3s_version, '<')
18+
when: k3s_upgrade_current_version is version(k3s_version, '<')
1919
block:
2020
- name: Find K3s service files
21+
# noqa var-naming[no-role-prefix]
2122
ansible.builtin.find:
2223
paths: "{{ systemd_dir }}"
2324
patterns: "k3s*.service"

roles/prereq/tasks/main.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@
4444
ansible.builtin.command:
4545
cmd: ufw status
4646
changed_when: false
47-
register: ufw_status
47+
register: prereq_ufw_status
4848

4949
- name: If ufw enabled, open api port
5050
when:
51-
- "'Status: active' in ufw_status['stdout']"
51+
- "'Status: active' in prereq_ufw_status['stdout']"
5252
community.general.ufw:
5353
rule: allow
5454
port: "{{ api_port }}"
5555
proto: tcp
5656

5757
- name: If ufw enabled, open etcd ports
5858
when:
59-
- "'Status: active' in ufw_status['stdout']"
59+
- "'Status: active' in prereq_ufw_status['stdout']"
6060
- groups[server_group] | length > 1
6161
community.general.ufw:
6262
rule: allow
@@ -65,7 +65,7 @@
6565

6666
- name: If ufw enabled, allow default CIDRs
6767
when:
68-
- "'Status: active' in ufw_status['stdout']"
68+
- "'Status: active' in prereq_ufw_status['stdout']"
6969
community.general.ufw:
7070
rule: allow
7171
src: '{{ item }}'
@@ -162,19 +162,19 @@
162162
- name: Check for Apparmor existence
163163
ansible.builtin.stat:
164164
path: /sys/module/apparmor/parameters/enabled
165-
register: apparmor_enabled
165+
register: prereq_apparmor_enabled
166166

167167
- name: Check if Apparmor is enabled
168-
when: apparmor_enabled.stat.exists
168+
when: prereq_apparmor_enabled.stat.exists
169169
ansible.builtin.command: cat /sys/module/apparmor/parameters/enabled
170-
register: apparmor_status
170+
register: prereq_apparmor_status
171171
changed_when: false
172172

173173
- name: Install Apparmor Parser [Suse]
174174
when:
175175
- ansible_os_family == 'Suse'
176-
- apparmor_status is defined
177-
- apparmor_status.stdout == "Y"
176+
- prereq_apparmor_status is defined
177+
- prereq_apparmor_status.stdout == "Y"
178178
ansible.builtin.package:
179179
name: apparmor-parser
180180
state: present
@@ -183,8 +183,8 @@
183183
when:
184184
- ansible_distribution == 'Debian'
185185
- ansible_facts['distribution_major_version'] == "11"
186-
- apparmor_status is defined
187-
- apparmor_status.stdout == "Y"
186+
- prereq_apparmor_status is defined
187+
- prereq_apparmor_status.stdout == "Y"
188188
ansible.builtin.package:
189189
name: apparmor
190190
state: present

roles/raspberrypi/tasks/main.yml

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,48 @@
11
---
22
- name: Test for raspberry pi /proc/cpuinfo
33
ansible.builtin.command: grep -E "Raspberry Pi|BCM2708|BCM2709|BCM2835|BCM2836" /proc/cpuinfo
4-
register: grep_cpuinfo_raspberrypi
4+
register: raspberrypi_grep_cpuinfo
55
failed_when: false
66
changed_when: false
77

88
- name: Test for raspberry pi /proc/device-tree/model
99
ansible.builtin.command: grep -E "Raspberry Pi" /proc/device-tree/model
10-
register: grep_device_tree_model_raspberrypi
10+
register: raspberrypi_grep_device_tree_model
1111
failed_when: false
1212
changed_when: false
1313

14-
- name: Set raspberry_pi fact to true
15-
ansible.builtin.set_fact:
16-
raspberry_pi: true
14+
- name: Run Raspberry Pi-specific tasks
1715
when:
18-
grep_cpuinfo_raspberrypi.rc == 0 or grep_device_tree_model_raspberrypi.rc == 0
16+
- raspberrypi_grep_cpuinfo.rc == 0 or raspberrypi_grep_device_tree_model.rc == 0
17+
block:
18+
- name: Set detected_distribution to Raspbian
19+
# noqa var-naming[no-role-prefix]
20+
ansible.builtin.set_fact:
21+
detected_distribution: Raspbian
22+
when: >
23+
ansible_facts.lsb.id|default("") == "Raspbian" or
24+
ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*")
1925
20-
- name: Set detected_distribution to Raspbian
21-
ansible.builtin.set_fact:
22-
detected_distribution: Raspbian
23-
when: >
24-
raspberry_pi|default(false) and
25-
( ansible_facts.lsb.id|default("") == "Raspbian" or
26-
ansible_facts.lsb.description|default("") is match("[Rr]aspbian.*") )
26+
- name: Set detected_distribution to Debian
27+
# noqa var-naming[no-role-prefix]
28+
ansible.builtin.set_fact:
29+
detected_distribution: Debian
30+
when: >
31+
ansible_facts.lsb.id|default("") == "Debian" or
32+
ansible_facts.lsb.description|default("") is match("Debian")
2733
28-
- name: Set detected_distribution to Debian
29-
ansible.builtin.set_fact:
30-
detected_distribution: Debian
31-
when: >
32-
raspberry_pi|default(false) and
33-
( ansible_facts.lsb.id|default("") == "Debian" or
34-
ansible_facts.lsb.description|default("") is match("Debian") )
34+
- name: Set detected_distribution to ArchLinux (ARM64)
35+
# noqa var-naming[no-role-prefix]
36+
ansible.builtin.set_fact:
37+
detected_distribution: Archlinux
38+
when:
39+
- ansible_facts.architecture is search("aarch64")
40+
- ansible_facts.os_family is match("Archlinux")
3541

36-
- name: Set detected_distribution to ArchLinux (ARM64)
37-
ansible.builtin.set_fact:
38-
detected_distribution: Archlinux
39-
when:
40-
- ansible_facts.architecture is search("aarch64")
41-
- raspberry_pi|default(false)
42-
- ansible_facts.os_family is match("Archlinux")
43-
44-
- name: Execute OS related tasks on the Raspberry Pi
45-
ansible.builtin.include_tasks: "{{ item }}"
46-
with_first_found:
47-
- "prereq/{{ detected_distribution }}.yml"
48-
- "prereq/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
49-
- "prereq/{{ ansible_distribution }}.yml"
50-
- "prereq/default.yml"
51-
when:
52-
- raspberry_pi|default(false)
42+
- name: Execute OS related tasks on the Raspberry Pi
43+
ansible.builtin.include_tasks: "{{ item }}"
44+
with_first_found:
45+
- "prereq/{{ detected_distribution }}.yml"
46+
- "prereq/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
47+
- "prereq/{{ ansible_distribution }}.yml"
48+
- "prereq/default.yml"

0 commit comments

Comments
 (0)