chore: migrate bare ansible_* facts to ansible_facts[] syntax
All checks were successful
ci/woodpecker/push/linting Pipeline was successful

This commit is contained in:
Simon Cornet 2026-05-19 09:19:03 +02:00
commit 2272aa6a58
23 changed files with 70 additions and 70 deletions

View file

@ -2,7 +2,7 @@
# manage packages
- name: "manage packages"
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'
become: true
block:
@ -29,7 +29,7 @@
community.general.apk:
name: "qemu-guest-agent"
state: "absent"
when: "ansible_virtualization_type == 'lxc'"
when: "ansible_facts['virtualization_type'] == 'lxc'"
# install qemu-guest-agent
@ -37,7 +37,7 @@
community.general.apk:
name: "qemu-guest-agent"
state: "present"
when: "ansible_virtualization_type == 'kvm'"
when: "ansible_facts['virtualization_type'] == 'kvm'"
# clean cache
- name: "clean cache"

View file

@ -11,11 +11,11 @@
clean: true
changed_when: false
failed_when: false
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
# run fstrim if target is a VM
- name: "fstrim"
ansible.builtin.command: "fstrim /"
changed_when: false
failed_when: false
when: "ansible_virtualization_type == 'kvm'"
when: "ansible_facts['virtualization_type'] == 'kvm'"

View file

@ -13,13 +13,13 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
- name: "apt - config - configure apt unatteded updates"
ansible.builtin.template:
src: "templates/apt/conf.d/50unattended-upgrades.{{ ansible_distribution }}.j2"
src: "templates/apt/conf.d/50unattended-upgrades.{{ ansible_facts['distribution'] }}.j2"
dest: "/etc/apt/apt.conf.d/50unattended-upgrades"
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'

View file

@ -11,7 +11,7 @@
name: "{{ apt_default_install }}"
state: "present"
update_cache: true
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
loop: "{{ apt_default_packages_install }}"
loop_control:
loop_var: "apt_default_install"
@ -22,7 +22,7 @@
name: "{{ apt_default_delete }}"
state: "absent"
purge: true
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
loop: "{{ apt_default_packages_delete }}"
loop_control:
loop_var: "apt_default_delete"

View file

@ -8,14 +8,14 @@
# configure legacy apt sources
- name: "configure legacy apt sources"
when: >
(ansible_distribution == "Debian" and ansible_distribution_major_version | int <= 12) or
(ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int <= 23)
(ansible_facts['distribution'] == "Debian" and ansible_facts['distribution_major_version'] | int <= 12) or
(ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] | int <= 23)
block:
# configure apt sources
- name: "apt - config - configure apt sources"
ansible.builtin.template:
src: "templates/apt/sources.d/{{ ansible_distribution | lower }}.sources.list.j2"
src: "templates/apt/sources.d/{{ ansible_facts['distribution'] | lower }}.sources.list.j2"
dest: "/etc/apt/sources.list"
owner: "root"
group: "root"
@ -25,15 +25,15 @@
# configure deb822 apt sources
- name: "configure deb822 apt sources"
when: >
(ansible_distribution == "Debian" and ansible_distribution_major_version | int >= 13) or
(ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int >= 24)
(ansible_facts['distribution'] == "Debian" and ansible_facts['distribution_major_version'] | int >= 13) or
(ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] | int >= 24)
block:
# configure apt sources
- name: "apt - config - configure apt sources"
ansible.builtin.template:
src: "templates/apt/sources.d/{{ ansible_distribution | lower }}.sources.j2"
dest: "/etc/apt/sources.list.d/{{ ansible_distribution | lower }}.sources"
src: "templates/apt/sources.d/{{ ansible_facts['distribution'] | lower }}.sources.j2"
dest: "/etc/apt/sources.list.d/{{ ansible_facts['distribution'] | lower }}.sources"
owner: "root"
group: "root"
mode: "0644"

View file

@ -3,7 +3,7 @@
# apt update
- name: "apt update"
tags: "apt-update"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
block:
# run apt update
@ -35,7 +35,7 @@
cmd: "fstrim /"
changed_when: false
failed_when: false
when: "ansible_virtualization_type == 'kvm'"
when: "ansible_facts['virtualization_type'] == 'kvm'"
# check for reboots
- name: "check if reboot required"

View file

@ -9,8 +9,8 @@
group: "root"
mode: "0644"
when:
- "ansible_os_family == 'Debian'"
- "ansible_virtualization_type == 'lxc'"
- "ansible_facts['os_family'] == 'Debian'"
- "ansible_facts['virtualization_type'] == 'lxc'"
tags: "cron"
# configure cron
@ -21,5 +21,5 @@
owner: "root"
group: "root"
mode: "0600"
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'
tags: "cron"

View file

@ -8,5 +8,5 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_distribution == "Ubuntu"'
when: 'ansible_facts["distribution"] == "Ubuntu"'
tags: "environment-file"

View file

@ -13,7 +13,7 @@
# manage firewall for debian
- name: "firewall - debian family"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
block:
# remove and disable firewall

View file

@ -11,5 +11,5 @@
dump: "0"
passno: "0"
when:
- "ansible_os_family == 'Alpine'"
- "ansible_facts['os_family'] == 'Alpine'"
- "'router' not in inventory_hostname"

View file

@ -11,8 +11,8 @@
- name: "manage /etc/hosts file for hostname"
ansible.builtin.lineinfile:
path: "/etc/hosts"
regexp: '^{{ ansible_default_ipv4.address }}\s+.*{{ inventory_hostname_short }}.*$'
line: "{{ ansible_default_ipv4.address }} {{ inventory_hostname }} {{ inventory_hostname_short }}"
regexp: '^{{ ansible_facts["default_ipv4"].address }}\s+.*{{ inventory_hostname_short }}.*$'
line: "{{ ansible_facts['default_ipv4'].address }} {{ inventory_hostname }} {{ inventory_hostname_short }}"
backup: true
tags:
- "hostfile"

View file

@ -8,6 +8,6 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_distribution == "Ubuntu"'
when: 'ansible_facts["distribution"] == "Ubuntu"'
notify: "restart journald"
tags: "journald"

View file

@ -6,6 +6,6 @@
name: "lldpd"
state: "present"
cache_valid_time: 3600
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
notify: "restart lldpd"
tags: "lldp"

View file

@ -6,5 +6,5 @@
name: "lxd"
state: "absent"
purge: true
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
tags: "lxd"

View file

@ -8,7 +8,7 @@
# load os variables
- name: "include os specific vars"
ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yaml"
ansible.builtin.include_vars: "vars/{{ ansible_facts['os_family'] }}.yaml"
tags: "always"
# set dns
@ -19,13 +19,13 @@
# set hostname
- name: "set hostname"
ansible.builtin.import_tasks: "hostname.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "hostname"
# set locale
- name: "set locale"
ansible.builtin.import_tasks: "locale.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "locale"
# environment
@ -47,8 +47,8 @@
- name: "swap"
ansible.builtin.import_tasks: "swap.yaml"
when:
- "ansible_os_family =='Debian'"
- "ansible_virtualization_type == 'kvm'"
- "ansible_facts['os_family'] =='Debian'"
- "ansible_facts['virtualization_type'] == 'kvm'"
tags: "swap"
# manage fstab
@ -59,13 +59,13 @@
# apk
- name: "apk"
ansible.builtin.import_tasks: "apk/packages.yaml"
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'
tags: "apk"
# apt
- name: "apt"
ansible.builtin.import_tasks: "apt/sources.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "apt"
# flush handler
@ -74,22 +74,22 @@
- name: "apt - update"
ansible.builtin.import_tasks: "apt/update.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "apt-update"
- name: "apt - packages"
ansible.builtin.import_tasks: "apt/packages.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "apt"
- name: "apt - config"
ansible.builtin.import_tasks: "apt/config.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "apt"
- name: "apt - cleanup"
ansible.builtin.import_tasks: "apt/cleanup.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "apt-cleanup"
# manage profile
@ -100,7 +100,7 @@
# telemetry
- name: "telemetry"
ansible.builtin.import_tasks: "telemetry.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "telemetry"
# service
@ -111,7 +111,7 @@
loop_var: "__service"
when:
- "service is defined"
- "ansible_os_family == 'Debian'"
- "ansible_facts['os_family'] == 'Debian'"
# flush handler
- name: "flush handlers"
@ -120,7 +120,7 @@
# chrony
- name: "ntp"
ansible.builtin.import_tasks: "ntp.yaml"
when: "ansible_virtualization_type in ['kvm', 'none']"
when: "ansible_facts['virtualization_type'] in ['kvm', 'none']"
tags: "ntp"
# flush handler
@ -130,22 +130,22 @@
# snap
- name: "snap - daemon"
ansible.builtin.import_tasks: "snap/snap_daemon.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "snap"
- name: "snap - package"
ansible.builtin.import_tasks: "snap/snap_package.yaml"
when:
- "snap_package is defined"
- "ansible_os_family == 'Debian'"
- "ansible_facts['os_family'] == 'Debian'"
tags: "snap"
# lxd
- name: "lxd"
ansible.builtin.import_tasks: "lxd.yaml"
when:
- "ansible_os_family =='Debian'"
- "ansible_virtualization_type == 'kvm'"
- "ansible_facts['os_family'] =='Debian'"
- "ansible_facts['virtualization_type'] == 'kvm'"
tags: "lxd"
# flush handler
@ -155,7 +155,7 @@
# sysctl
- name: "sysctl - set sysctl"
ansible.builtin.import_tasks: "sysctl.yaml"
when: "ansible_virtualization_type in ['kvm', 'none']"
when: "ansible_facts['virtualization_type'] in ['kvm', 'none']"
tags: "sysctl"
# systemctl
@ -165,8 +165,8 @@
loop_control:
loop_var: "__systemctl"
when:
- "ansible_os_family =='Debian'"
- "ansible_virtualization_type == 'kvm'"
- "ansible_facts['os_family'] =='Debian'"
- "ansible_facts['virtualization_type'] == 'kvm'"
tags: "systemctl"
# syslog
@ -185,7 +185,7 @@
# journald
- name: "journald"
ansible.builtin.import_tasks: "journald.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "journald"
# flush handler
@ -217,5 +217,5 @@
# firewall
- name: "firewall"
ansible.builtin.import_tasks: "firewall.yaml"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
tags: "firewall"

View file

@ -6,7 +6,7 @@
# cleanup old motd debian
- name: "cleanup old motd debian"
when: "ansible_os_family == 'Debian'"
when: "ansible_facts['os_family'] == 'Debian'"
block:
# find old motd files
@ -41,7 +41,7 @@
owner: "root"
group: "root"
mode: "0755"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
# configure motd
- name: "motd - siempie - alpine"
@ -51,4 +51,4 @@
owner: "root"
group: "root"
mode: "0755"
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'

View file

@ -10,7 +10,7 @@
name: "chrony"
state: "present"
update_cache: true
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'
# create keys file
- name: "ntp - chrony keys file"
@ -21,14 +21,14 @@
mode: "0440"
state: "touch"
notify: "restart chrony"
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'
# install chrony
- name: "ntp - install - chrony debian"
ansible.builtin.apt:
name: "chrony"
state: "present"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
# configure chrony
- name: "ntp - config - configure chrony"

View file

@ -7,4 +7,4 @@
line: "export PS1='\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '"
create: true
mode: "0644"
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'

View file

@ -9,7 +9,7 @@
group: "root"
mode: "0644"
notify: "restart ssh"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
tags: "sshd"
# configure sshd
@ -21,5 +21,5 @@
group: "root"
mode: "0644"
notify: "restart ssh alpine"
when: 'ansible_os_family == "Alpine"'
when: 'ansible_facts["os_family"] == "Alpine"'
tags: "sshd"

View file

@ -13,7 +13,7 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_distribution == "Alpine"'
when: 'ansible_facts["distribution"] == "Alpine"'
notify: "restart syslog alpine"
# configure rsyslogd - debian
@ -24,7 +24,7 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_distribution == "Debian"'
when: 'ansible_facts["distribution"] == "Debian"'
notify: "restart rsyslog"
# configure rsyslogd - ubuntu
@ -35,7 +35,7 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_distribution == "Ubuntu"'
when: 'ansible_facts["distribution"] == "Ubuntu"'
notify: "restart rsyslog"
# configure rsyslogd - apt
@ -46,7 +46,7 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
notify: "restart rsyslog"
# configure rsyslogd
@ -57,5 +57,5 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
notify: "restart rsyslog"

View file

@ -6,5 +6,5 @@
name: "rsyslog"
state: "present"
cache_valid_time: 3600
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
tags: "syslog"

View file

@ -8,6 +8,6 @@
owner: "root"
group: "root"
mode: "0644"
when: 'ansible_os_family == "Debian"'
when: 'ansible_facts["os_family"] == "Debian"'
notify: "daemon-reload fstrim.timer"
tags: "systemctl"

View file

@ -5,5 +5,5 @@
ansible.builtin.file:
path: "/etc/cron.daily/popularity-contest"
state: "absent"
when: 'ansible_distribution == "Ubuntu"'
when: 'ansible_facts["distribution"] == "Ubuntu"'
tags: "telemetry"