feat: use builtin virtualisation detection

This commit is contained in:
Simon Cornet 2026-04-10 14:23:17 +02:00
commit 02d15fb57a
6 changed files with 15 additions and 14 deletions

View file

@ -29,14 +29,15 @@
community.general.apk: community.general.apk:
name: "qemu-guest-agent" name: "qemu-guest-agent"
state: "absent" state: "absent"
when: 'type == "lxc"' when: "ansible_virtualization_type == 'lxc'"
# install qemu-guest-agent # install qemu-guest-agent
- name: "install qemu-guest-agent" - name: "install qemu-guest-agent"
community.general.apk: community.general.apk:
name: "qemu-guest-agent" name: "qemu-guest-agent"
state: "present" state: "present"
when: 'type == "vm"' when: "ansible_virtualization_type == 'kvm'"
# clean cache # clean cache
- name: "clean cache" - name: "clean cache"

View file

@ -18,4 +18,4 @@
ansible.builtin.command: "fstrim /" ansible.builtin.command: "fstrim /"
changed_when: false changed_when: false
failed_when: false failed_when: false
when: 'type == "vm"' when: "ansible_virtualization_type == 'kvm'"

View file

@ -35,7 +35,7 @@
cmd: "fstrim /" cmd: "fstrim /"
changed_when: false changed_when: false
failed_when: false failed_when: false
when: 'type == "vm"' when: "ansible_virtualization_type == 'kvm'"
# check for reboots # check for reboots
- name: "check if reboot required" - name: "check if reboot required"

View file

@ -9,8 +9,8 @@
group: "root" group: "root"
mode: "0644" mode: "0644"
when: when:
- 'type == "lxc"'
- "ansible_os_family == 'Debian'" - "ansible_os_family == 'Debian'"
- "ansible_virtualization_type == 'lxc'"
tags: "cron" tags: "cron"
# configure cron # configure cron

View file

@ -42,8 +42,8 @@
- name: "swap" - name: "swap"
ansible.builtin.import_tasks: "swap.yaml" ansible.builtin.import_tasks: "swap.yaml"
when: when:
- 'type == "vm"'
- "ansible_os_family =='Debian'" - "ansible_os_family =='Debian'"
- "ansible_virtualization_type == 'kvm'"
tags: "swap" tags: "swap"
@ -116,7 +116,7 @@
# chrony # chrony
- name: "ntp" - name: "ntp"
ansible.builtin.import_tasks: "ntp.yaml" ansible.builtin.import_tasks: "ntp.yaml"
when: 'type == "vm" or type == "hw"' when: "ansible_virtualization_type == 'kvm'"
tags: "ntp" tags: "ntp"
# flush handler # flush handler
@ -140,8 +140,8 @@
- name: "lxd" - name: "lxd"
ansible.builtin.import_tasks: "lxd.yaml" ansible.builtin.import_tasks: "lxd.yaml"
when: when:
- 'type == "vm"' - "ansible_os_family =='Debian'"
- "ansible_os_family == 'Debian'" - "ansible_virtualization_type == 'kvm'"
tags: "lxd" tags: "lxd"
# flush handler # flush handler
@ -151,7 +151,7 @@
# sysctl # sysctl
- name: "sysctl - set sysctl" - name: "sysctl - set sysctl"
ansible.builtin.import_tasks: "sysctl.yaml" ansible.builtin.import_tasks: "sysctl.yaml"
when: 'type == "vm" or type == "hw"' when: "ansible_virtualization_type == 'kvm'"
tags: "sysctl" tags: "sysctl"
# systemctl # systemctl
@ -161,8 +161,8 @@
loop_control: loop_control:
loop_var: "__systemctl" loop_var: "__systemctl"
when: when:
- 'type == "vm"' - "ansible_os_family =='Debian'"
- "ansible_os_family == 'Debian'" - "ansible_virtualization_type == 'kvm'"
tags: "systemctl" tags: "systemctl"
# syslog # syslog

View file

@ -9,10 +9,10 @@
# disable swap # disable swap
@reboot swapoff -a @reboot swapoff -a
{% if type == 'vm' %} {% if ansible_virtualization_type == 'kvm' %}
# flush caches every 2 hours # flush caches every 2 hours
0 */2 * * * echo 3 > /proc/sys/vm/drop_caches 0 */2 * * * echo 3 > /proc/sys/vm/drop_caches
{% endif %} {% endif %}
# update packages between 3:15-3:30 am # update packages on sunday between 3:15-3:30 am
15 3 * * 0 sleep $(($RANDOM % 900)) && apk -U upgrade >/dev/null 2>&1 && apk clean cache && reboot -d 60 15 3 * * 0 sleep $(($RANDOM % 900)) && apk -U upgrade >/dev/null 2>&1 && apk clean cache && reboot -d 60