From 4215bb8398de6e6822b6eee4b353670473cbe2fc Mon Sep 17 00:00:00 2001 From: Chris Croome <chris@webarchitects.co.uk> Date: Wed, 17 May 2023 16:44:23 +0100 Subject: [PATCH] Fix install / remove packages --- .pre-commit-config.yaml | 2 +- tasks/main.yml | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3663620..bc4bf24 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 aef747c..8c38137 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 -- GitLab