diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 3663620d6d404a30dc9ea2dde5b6404363540de5..bc4bf24f5a03231449ffe177cab18107358ed7be 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -12,7 +12,7 @@
 # https://github.com/adrienverge/yamllint/tags
 repos:
   - repo: https://github.com/adrienverge/yamllint.git
-    rev: v1.30.0
+    rev: v1.31.0
     hooks:
       - id: yamllint
 ...
diff --git a/tasks/main.yml b/tasks/main.yml
index aef747cbf49efc15e08763e834e2e261059c3e33..8c38137b5b669bfed33ecc6d0912b84e31016c9a 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -34,6 +34,11 @@
             pkg: "{{ apache_packages_absent }}"
             state: absent
             update_cache: false
+          when:
+            - apache_packages_absent is defined
+            - apache_packages_absent != []
+            - ansible_local.dpkg.installed is defined
+            - apache_packages_absent | ansible.builtin.intersect(ansible_local.dpkg.installed) != []
 
         - name: Apache present from buster-backports
           ansible.builtin.apt:
@@ -44,6 +49,7 @@
             default_release: buster-backports
             update_cache: true
           when:
+            - apache_packages_present is defined
             - ( "apache2" in apache_pkgs_present )
             - ansible_distribution_release == "buster"
 
@@ -53,12 +59,15 @@
             state: present
             install_recommends: true
             update_cache: false
+          when:
+            - apache_packages_present is defined
+            - apache_packages_present != []
+            - ansible_local.dpkg.installed is defined
+            - apache_packages_present | ansible.builtin.difference(ansible_local.dpkg.installed) != []
 
       when: >-
-        ( ( apache_pkgs_absent is defined ) and ( apache_pkgs_absent != [] ) and
-        ( apache_pkgs_absent | ansible.builtin.intersect(ansible_local.dpkg.installed) != [] ) ) or
-        ( ( apache_pkgs_present is defined ) and ( apache_pkgs_present != [] ) and
-        ( apache_pkgs_present | ansible.builtin.difference(ansible_local.dpkg.installed) != [] ) )
+        ( ( apache_pkgs_absent is defined ) and ( apache_pkgs_absent != [] ) or
+        ( ( apache_pkgs_present is defined ) and ( apache_pkgs_present != [] )
 
     - name: Include local facts tasks
       ansible.builtin.include_tasks: local_facts.yml