From fdaa62d7a98dc38f4d3f86508ffcc40720c4caa3 Mon Sep 17 00:00:00 2001
From: "Adrien \"ze\" Urban" <aur@nbs-system.com>
Date: Tue, 3 Jul 2018 11:34:21 +0200
Subject: [PATCH] vhosts/cleanup: clean non-salted sites

Makes it easier to clean any unwanted sites
---
 apache/vhosts/cleanup.sls | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 apache/vhosts/cleanup.sls

diff --git a/apache/vhosts/cleanup.sls b/apache/vhosts/cleanup.sls
new file mode 100644
index 0000000..83b7fa8
--- /dev/null
+++ b/apache/vhosts/cleanup.sls
@@ -0,0 +1,37 @@
+{% from "apache/map.jinja" import apache with context %}
+
+include:
+  - apache
+
+{% if grains.os_family == 'Debian' %}
+
+{% set dirpath = '/etc/apache2/sites-enabled' %}
+
+{# Add . and .. to make it easier to not clean those #}
+{% set valid_sites = ['.', '..', ] %}
+
+{# Take sites from apache.vhosts.standard #}
+{% for id, site in salt['pillar.get']('apache:sites', {}).items() %}
+{%   do valid_sites.append('{}{}'.format(id, apache.confext)) %}
+{% endfor %}
+
+{# Take sites from apache.register_site #}
+{% for id, site in salt['pillar.get']('apache:register-site', {}) %}
+{%   do valid_sites.append('{}{}'.format(site.name, apache.confext)) %}
+{% endfor %}
+
+
+{% for filename in salt['file.readdir']('/etc/apache2/sites-enabled/') %}
+{%   if filename not in valid_sites %}
+
+a2dissite {{ filename }}:
+  cmd.run:
+    - onlyif: "test -L {{ dirpath}}/{{ filename }} || test -f {{ dirpath}}/{{ filename }}"
+    - watch_in:
+      - module: apache-reload
+
+{%   endif %}
+{% endfor %}
+
+
+{% endif %}{# Debian #}
-- 
GitLab