From 306d00c97eb7f53889d5cfbb303dc62f421dfee5 Mon Sep 17 00:00:00 2001
From: Chris Croome <chris@webarchitects.co.uk>
Date: Wed, 13 Apr 2022 17:10:19 +0100
Subject: [PATCH] remove config files when removing versions

---
 defaults/main.yml |  4 ++--
 tasks/absent.yml  | 12 +++++++++++-
 tasks/checks.yml  |  3 +++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/defaults/main.yml b/defaults/main.yml
index c33107c..70affad 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -4,14 +4,14 @@ php_dpkg: /usr/bin/dpkg
 php_phpquery: /usr/sbin/phpquery
 php_versions:
   '8.1':
-    state: absent
+    state: present
     sapis:
       apache2:
         state: absent
       cli:
         state: present
       fpm:
-        state: present
+        state: absent
       phpdbg:
         state: absent
   '8.0':
diff --git a/tasks/absent.yml b/tasks/absent.yml
index 65659e6..125a8e2 100644
--- a/tasks/absent.yml
+++ b/tasks/absent.yml
@@ -6,12 +6,22 @@
       apt:
         pkg: "php{{ version }}*"
         state: absent
+        purge: true
         autoclean: true
         autoremove: true
       loop: "{{ php_versions_remove }}"
       loop_control:
         loop_var: version
-        label: "php{{ version }}"
+        label: "{{ version }}"
+
+    - name: PHP config files absent
+      file:
+        path: "/etc/php/{{ version }}/"
+        state: absent
+      loop: "{{ php_versions_remove }}"
+      loop_control:
+        loop_var: version
+        label: "{{ version }}"
 
   tags:
     - php
diff --git a/tasks/checks.yml b/tasks/checks.yml
index fe1fe90..e26ba2a 100644
--- a/tasks/checks.yml
+++ b/tasks/checks.yml
@@ -2,6 +2,9 @@
 - name: PHP checks
   block:
 
+    # TODO
+    # - Check that when a version SAPI is set to present the version is also set to present
+    # - Check that when a version is set to absent the SAPIs are also set to absent, if the state is set
     - name: Check that depreciated variables are not used
       assert:
         that:
-- 
GitLab