mirror of
https://github.com/k3s-io/k3s-ansible.git
synced 2025-12-26 00:22:36 +01:00
fix(ansible): replace deprecated entities and sync version requirements (#478)
* refactor(ansible): replace deprecated with_items and ansible facts Replace deprecated `with_items` with `loop` keyword across all roles. Migrate from legacy `ansible_*` top-level facts to `ansible_facts['*']` syntax to prepare for ansible-core 2.24 where INJECT_FACTS_AS_VARS will default to False. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la> * chore(ansible): sync minimum version requirements to 2.15 Align version checks in prereq and airgap roles with README requirement of ansible-core 2.15+. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la> --------- Signed-off-by: Aleksei Sviridkin <f@lex.la> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
e11ff62d8f
commit
826c53975d
@@ -9,8 +9,8 @@
|
|||||||
block:
|
block:
|
||||||
- name: Verify Ansible meets airgap version requirements.
|
- name: Verify Ansible meets airgap version requirements.
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that: "ansible_version.full is version_compare('2.12', '>=')"
|
that: "ansible_version.full is version_compare('2.15', '>=')"
|
||||||
msg: "The Airgap role requires at least ansible-core 2.12"
|
msg: "The Airgap role requires at least ansible-core 2.15"
|
||||||
|
|
||||||
- name: Check for existing install script
|
- name: Check for existing install script
|
||||||
become: false
|
become: false
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
- name: Determine architecture and set airgap_k3s_arch
|
- name: Determine architecture and set airgap_k3s_arch
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
airgap_k3s_arch: "{{ 'arm64' if ansible_architecture == 'aarch64' else 'arm' if ansible_architecture == 'armv7l' else 'amd64' }}"
|
airgap_k3s_arch: "{{ 'arm64' if ansible_facts['architecture'] == 'aarch64' else 'arm' if ansible_facts['architecture'] == 'armv7l' else 'amd64' }}"
|
||||||
|
|
||||||
- name: Distribute K3s binary
|
- name: Distribute K3s binary
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
- name: Install K3s SELinux RPM
|
- name: Install K3s SELinux RPM
|
||||||
when:
|
when:
|
||||||
- ansible_os_family == 'RedHat'
|
- ansible_facts['os_family'] == 'RedHat'
|
||||||
- airgap_selinux_copy.skipped is false
|
- airgap_selinux_copy.skipped is false
|
||||||
ansible.builtin.dnf:
|
ansible.builtin.dnf:
|
||||||
name: "{{ airgap_selinux_copy.results[0].dest }}"
|
name: "{{ airgap_selinux_copy.results[0].dest }}"
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "{{ systemd_dir }}/k3s-agent.service.env"
|
path: "{{ systemd_dir }}/k3s-agent.service.env"
|
||||||
line: "{{ item }}"
|
line: "{{ item }}"
|
||||||
with_items: "{{ extra_service_envs }}"
|
loop: "{{ extra_service_envs }}"
|
||||||
|
|
||||||
- name: Delete any existing token from the environment if different from the new one
|
- name: Delete any existing token from the environment if different from the new one
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "{{ systemd_dir }}/k3s-agent.service.env"
|
path: "{{ systemd_dir }}/k3s-agent.service.env"
|
||||||
line: "{{ item }}"
|
line: "{{ item }}"
|
||||||
with_items:
|
loop:
|
||||||
- "K3S_TOKEN={{ token }}"
|
- "K3S_TOKEN={{ token }}"
|
||||||
|
|
||||||
- name: Modify ExecStart in k3s-agent.service to include API endpoint and extra args
|
- name: Modify ExecStart in k3s-agent.service to include API endpoint and extra args
|
||||||
|
|||||||
@@ -127,7 +127,7 @@
|
|||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "{{ systemd_dir }}/k3s.service.env"
|
path: "{{ systemd_dir }}/k3s.service.env"
|
||||||
line: "{{ item }}"
|
line: "{{ item }}"
|
||||||
with_items: "{{ extra_service_envs }}"
|
loop: "{{ extra_service_envs }}"
|
||||||
|
|
||||||
- name: Delete any existing token from the environment if different from the new one
|
- name: Delete any existing token from the environment if different from the new one
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
@@ -261,7 +261,7 @@
|
|||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "{{ systemd_dir }}/k3s.service.env"
|
path: "{{ systemd_dir }}/k3s.service.env"
|
||||||
line: "{{ item }}"
|
line: "{{ item }}"
|
||||||
with_items: "{{ extra_service_envs }}"
|
loop: "{{ extra_service_envs }}"
|
||||||
|
|
||||||
- name: Delete any existing token from the environment if different from the new one
|
- name: Delete any existing token from the environment if different from the new one
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
@@ -274,7 +274,7 @@
|
|||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "{{ systemd_dir }}/k3s.service.env"
|
path: "{{ systemd_dir }}/k3s.service.env"
|
||||||
line: "{{ item }}"
|
line: "{{ item }}"
|
||||||
with_items:
|
loop:
|
||||||
- "K3S_TOKEN={{ token }}"
|
- "K3S_TOKEN={{ token }}"
|
||||||
|
|
||||||
# When using an external database, no join is needed, instead, users should be
|
# When using an external database, no join is needed, instead, users should be
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
- name: Enforce minimum Ansible version
|
- name: Enforce minimum Ansible version
|
||||||
ansible.builtin.assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- ansible_version.full is version('2.14', '>=')
|
- ansible_version.full is version('2.15', '>=')
|
||||||
msg: "Minimum ansible-core version required is 2.14"
|
msg: "Minimum ansible-core version required is 2.15"
|
||||||
|
|
||||||
- name: Install Dependent Ubuntu Packages
|
- name: Install Dependent Ubuntu Packages
|
||||||
when: ansible_distribution in ['Ubuntu']
|
when: ansible_facts['distribution'] in ['Ubuntu']
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: policycoreutils # Used by install script to restore SELinux context
|
name: policycoreutils # Used by install script to restore SELinux context
|
||||||
update_cache: "{{ airgap_dir is not defined }}"
|
update_cache: "{{ airgap_dir is not defined }}"
|
||||||
|
|
||||||
- name: Install Dependent RHEL 10 Package
|
- name: Install Dependent RHEL 10 Package
|
||||||
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == "10"
|
when: ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == "10"
|
||||||
ansible.builtin.dnf:
|
ansible.builtin.dnf:
|
||||||
name: kernel-modules-extra # Load br_netfilter module
|
name: kernel-modules-extra # Load br_netfilter module
|
||||||
update_cache: "{{ airgap_dir is not defined }}"
|
update_cache: "{{ airgap_dir is not defined }}"
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
value: "1"
|
value: "1"
|
||||||
state: present
|
state: present
|
||||||
reload: true
|
reload: true
|
||||||
when: ansible_all_ipv6_addresses | length > 0
|
when: ansible_facts['all_ipv6_addresses'] | length > 0
|
||||||
|
|
||||||
- name: Populate service facts
|
- name: Populate service facts
|
||||||
ansible.builtin.service_facts:
|
ansible.builtin.service_facts:
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
state: enabled
|
state: enabled
|
||||||
permanent: true
|
permanent: true
|
||||||
immediate: true
|
immediate: true
|
||||||
with_items:
|
loop:
|
||||||
- 5001/tcp # Spegel (Embedded distributed registry)
|
- 5001/tcp # Spegel (Embedded distributed registry)
|
||||||
- 8472/udp # Flannel VXLAN
|
- 8472/udp # Flannel VXLAN
|
||||||
- 10250/tcp # Kubelet metrics
|
- 10250/tcp # Kubelet metrics
|
||||||
@@ -135,8 +135,8 @@
|
|||||||
+ groups[agent_group] | default([])
|
+ groups[agent_group] | default([])
|
||||||
)
|
)
|
||||||
| map('extract', hostvars)
|
| map('extract', hostvars)
|
||||||
| selectattr('ansible_default_ipv4', 'defined')
|
| selectattr('ansible_facts.default_ipv4', 'defined')
|
||||||
| map(attribute='ansible_default_ipv4.address')
|
| map(attribute='ansible_facts.default_ipv4.address')
|
||||||
| flatten | unique | list
|
| flatten | unique | list
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -154,13 +154,13 @@
|
|||||||
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_os_family == 'RedHat' or ansible_distribution == 'Archlinux')
|
when: (ansible_facts['os_family'] == 'RedHat' or ansible_facts['distribution'] == 'Archlinux')
|
||||||
|
|
||||||
- name: Load br_netfilter
|
- name: Load br_netfilter
|
||||||
community.general.modprobe:
|
community.general.modprobe:
|
||||||
name: br_netfilter
|
name: br_netfilter
|
||||||
state: present
|
state: present
|
||||||
when: (ansible_os_family == 'RedHat' or ansible_distribution == 'Archlinux')
|
when: (ansible_facts['os_family'] == 'RedHat' or ansible_facts['distribution'] == 'Archlinux')
|
||||||
|
|
||||||
- name: Set bridge-nf-call-iptables (just to be sure)
|
- name: Set bridge-nf-call-iptables (just to be sure)
|
||||||
ansible.posix.sysctl:
|
ansible.posix.sysctl:
|
||||||
@@ -168,7 +168,7 @@
|
|||||||
value: "1"
|
value: "1"
|
||||||
state: present
|
state: present
|
||||||
reload: true
|
reload: true
|
||||||
when: (ansible_os_family == 'RedHat' or ansible_distribution == 'Archlinux')
|
when: (ansible_facts['os_family'] == 'RedHat' or ansible_facts['distribution'] == 'Archlinux')
|
||||||
loop:
|
loop:
|
||||||
- net.bridge.bridge-nf-call-iptables
|
- net.bridge.bridge-nf-call-iptables
|
||||||
- net.bridge.bridge-nf-call-ip6tables
|
- net.bridge.bridge-nf-call-ip6tables
|
||||||
@@ -186,7 +186,7 @@
|
|||||||
|
|
||||||
- name: Install Apparmor Parser [Suse]
|
- name: Install Apparmor Parser [Suse]
|
||||||
when:
|
when:
|
||||||
- ansible_os_family == 'Suse'
|
- ansible_facts['os_family'] == 'Suse'
|
||||||
- prereq_apparmor_status is defined
|
- prereq_apparmor_status is defined
|
||||||
- prereq_apparmor_status.stdout == "Y"
|
- prereq_apparmor_status.stdout == "Y"
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
@@ -195,7 +195,7 @@
|
|||||||
|
|
||||||
- name: Install Apparmor Parser [Debian]
|
- name: Install Apparmor Parser [Debian]
|
||||||
when:
|
when:
|
||||||
- ansible_distribution == 'Debian'
|
- ansible_facts['distribution'] == 'Debian'
|
||||||
- ansible_facts['distribution_major_version'] == "11"
|
- ansible_facts['distribution_major_version'] == "11"
|
||||||
- prereq_apparmor_status is defined
|
- prereq_apparmor_status is defined
|
||||||
- prereq_apparmor_status.stdout == "Y"
|
- prereq_apparmor_status.stdout == "Y"
|
||||||
@@ -227,7 +227,7 @@
|
|||||||
insertafter: EOF
|
insertafter: EOF
|
||||||
path: /etc/sudoers
|
path: /etc/sudoers
|
||||||
validate: 'visudo -cf %s'
|
validate: 'visudo -cf %s'
|
||||||
when: ansible_os_family == 'RedHat'
|
when: ansible_facts['os_family'] == 'RedHat'
|
||||||
|
|
||||||
- name: Setup alternative K3s directory
|
- name: Setup alternative K3s directory
|
||||||
when:
|
when:
|
||||||
|
|||||||
@@ -43,6 +43,6 @@
|
|||||||
ansible.builtin.include_tasks: "{{ item }}"
|
ansible.builtin.include_tasks: "{{ item }}"
|
||||||
with_first_found:
|
with_first_found:
|
||||||
- "prereq/{{ detected_distribution }}.yml"
|
- "prereq/{{ detected_distribution }}.yml"
|
||||||
- "prereq/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
- "prereq/{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yml"
|
||||||
- "prereq/{{ ansible_distribution }}.yml"
|
- "prereq/{{ ansible_facts['distribution'] }}.yml"
|
||||||
- "prereq/default.yml"
|
- "prereq/default.yml"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
path: /boot/boot.txt
|
path: /boot/boot.txt
|
||||||
regexp: '^(setenv bootargs console=ttyS1,115200 console=tty0 root=PARTUUID=\${uuid} rw rootwait smsc95xx.macaddr="\${usbethaddr}"(?!.*\b{{ cgroup_item }}\b).*)$'
|
regexp: '^(setenv bootargs console=ttyS1,115200 console=tty0 root=PARTUUID=\${uuid} rw rootwait smsc95xx.macaddr="\${usbethaddr}"(?!.*\b{{ cgroup_item }}\b).*)$'
|
||||||
replace: '\1 {{ cgroup_item }}'
|
replace: '\1 {{ cgroup_item }}'
|
||||||
with_items:
|
loop:
|
||||||
- "cgroup_enable=cpuset"
|
- "cgroup_enable=cpuset"
|
||||||
- "cgroup_memory=1"
|
- "cgroup_memory=1"
|
||||||
- "cgroup_enable=memory"
|
- "cgroup_enable=memory"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
path: /boot/cmdline.txt
|
path: /boot/cmdline.txt
|
||||||
regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
||||||
replace: '\1 {{ cgroup_item }}'
|
replace: '\1 {{ cgroup_item }}'
|
||||||
with_items:
|
loop:
|
||||||
- "cgroup_enable=cpuset"
|
- "cgroup_enable=cpuset"
|
||||||
- "cgroup_memory=1"
|
- "cgroup_memory=1"
|
||||||
- "cgroup_enable=memory"
|
- "cgroup_enable=memory"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
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: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
||||||
replace: '\1 {{ cgroup_item }}'
|
replace: '\1 {{ cgroup_item }}'
|
||||||
with_items:
|
loop:
|
||||||
- "cgroup_enable=cpuset"
|
- "cgroup_enable=cpuset"
|
||||||
- "cgroup_memory=1"
|
- "cgroup_memory=1"
|
||||||
- "cgroup_enable=memory"
|
- "cgroup_enable=memory"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
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: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
||||||
replace: '\1 {{ cgroup_item }}'
|
replace: '\1 {{ cgroup_item }}'
|
||||||
with_items:
|
loop:
|
||||||
- "cgroup_enable=cpuset"
|
- "cgroup_enable=cpuset"
|
||||||
- "cgroup_memory=1"
|
- "cgroup_memory=1"
|
||||||
- "cgroup_enable=memory"
|
- "cgroup_enable=memory"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
path: "{{ (boot_firmware_cmdline_txt.stat.exists) | ternary('/boot/firmware/cmdline.txt', '/boot/firmware/current/cmdline.txt') }}"
|
path: "{{ (boot_firmware_cmdline_txt.stat.exists) | ternary('/boot/firmware/cmdline.txt', '/boot/firmware/current/cmdline.txt') }}"
|
||||||
regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
regexp: '^([\w](?!.*\b{{ cgroup_item }}\b).*)$'
|
||||||
replace: '\1 {{ cgroup_item }}'
|
replace: '\1 {{ cgroup_item }}'
|
||||||
with_items:
|
loop:
|
||||||
- "cgroup_enable=cpuset"
|
- "cgroup_enable=cpuset"
|
||||||
- "cgroup_memory=1"
|
- "cgroup_memory=1"
|
||||||
- "cgroup_enable=memory"
|
- "cgroup_enable=memory"
|
||||||
@@ -24,4 +24,4 @@
|
|||||||
name: linux-modules-extra-raspi
|
name: linux-modules-extra-raspi
|
||||||
update_cache: "{{ airgap_dir is not defined }}"
|
update_cache: "{{ airgap_dir is not defined }}"
|
||||||
state: present
|
state: present
|
||||||
when: "ansible_distribution_version is version('20.10', '>=') and ansible_distribution_version is version('24.04', '<')"
|
when: "ansible_facts['distribution_version'] is version('20.10', '>=') and ansible_facts['distribution_version'] is version('24.04', '<')"
|
||||||
|
|||||||
Reference in New Issue
Block a user