diff --git a/tasks/apk/packages.yaml b/tasks/apk/packages.yaml index d09cd67..f6d5e2d 100644 --- a/tasks/apk/packages.yaml +++ b/tasks/apk/packages.yaml @@ -29,14 +29,15 @@ community.general.apk: name: "qemu-guest-agent" state: "absent" - when: 'type == "lxc"' + when: "ansible_virtualization_type == 'lxc'" + # install qemu-guest-agent - name: "install qemu-guest-agent" community.general.apk: name: "qemu-guest-agent" state: "present" - when: 'type == "vm"' + when: "ansible_virtualization_type == 'kvm'" # clean cache - name: "clean cache" diff --git a/tasks/apt/cleanup.yaml b/tasks/apt/cleanup.yaml index 3e6a1fa..1b2a4a0 100644 --- a/tasks/apt/cleanup.yaml +++ b/tasks/apt/cleanup.yaml @@ -18,4 +18,4 @@ ansible.builtin.command: "fstrim /" changed_when: false failed_when: false - when: 'type == "vm"' + when: "ansible_virtualization_type == 'kvm'" diff --git a/tasks/apt/update.yaml b/tasks/apt/update.yaml index 6fe4f4f..94ed44d 100644 --- a/tasks/apt/update.yaml +++ b/tasks/apt/update.yaml @@ -35,7 +35,7 @@ cmd: "fstrim /" changed_when: false failed_when: false - when: 'type == "vm"' + when: "ansible_virtualization_type == 'kvm'" # check for reboots - name: "check if reboot required" diff --git a/tasks/cron.yaml b/tasks/cron.yaml index 2a3845e..a7750da 100644 --- a/tasks/cron.yaml +++ b/tasks/cron.yaml @@ -9,8 +9,8 @@ group: "root" mode: "0644" when: - - 'type == "lxc"' - "ansible_os_family == 'Debian'" + - "ansible_virtualization_type == 'lxc'" tags: "cron" # configure cron diff --git a/tasks/main.yaml b/tasks/main.yaml index 96dacf9..30362aa 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -42,8 +42,8 @@ - name: "swap" ansible.builtin.import_tasks: "swap.yaml" when: - - 'type == "vm"' - "ansible_os_family =='Debian'" + - "ansible_virtualization_type == 'kvm'" tags: "swap" @@ -116,7 +116,7 @@ # chrony - name: "ntp" ansible.builtin.import_tasks: "ntp.yaml" - when: 'type == "vm" or type == "hw"' + when: "ansible_virtualization_type == 'kvm'" tags: "ntp" # flush handler @@ -140,8 +140,8 @@ - name: "lxd" ansible.builtin.import_tasks: "lxd.yaml" when: - - 'type == "vm"' - - "ansible_os_family == 'Debian'" + - "ansible_os_family =='Debian'" + - "ansible_virtualization_type == 'kvm'" tags: "lxd" # flush handler @@ -151,7 +151,7 @@ # sysctl - name: "sysctl - set sysctl" ansible.builtin.import_tasks: "sysctl.yaml" - when: 'type == "vm" or type == "hw"' + when: "ansible_virtualization_type == 'kvm'" tags: "sysctl" # systemctl @@ -161,8 +161,8 @@ loop_control: loop_var: "__systemctl" when: - - 'type == "vm"' - - "ansible_os_family == 'Debian'" + - "ansible_os_family =='Debian'" + - "ansible_virtualization_type == 'kvm'" tags: "systemctl" # syslog diff --git a/templates/cron/alpine-root.j2 b/templates/cron/alpine-root.j2 index 9ae5d2b..6cde4d7 100644 --- a/templates/cron/alpine-root.j2 +++ b/templates/cron/alpine-root.j2 @@ -9,10 +9,10 @@ # disable swap @reboot swapoff -a -{% if type == 'vm' %} +{% if ansible_virtualization_type == 'kvm' %} # flush caches every 2 hours 0 */2 * * * echo 3 > /proc/sys/vm/drop_caches {% 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