Saltstack Official Apache Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cleanup.sls 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. # vim: ft=sls
  3. {%- set tplroot = tpldir.split('/')[0] %}
  4. {%- set sls_service_running = tplroot ~ '.service.running' %}
  5. {%- from tplroot ~ "/map.jinja" import apache with context %}
  6. {%- if grains.os_family == 'Debian' %}
  7. include:
  8. - {{ sls_service_running }}
  9. {%- set dirpath = '/etc/apache2/sites-enabled' %}
  10. {# Add . and .. to make it easier to not clean those #}
  11. {%- set valid_sites = ['.', '..', ] %}
  12. {# Take sites from apache.vhosts.standard #}
  13. {%- for id, site in salt['pillar.get']('apache:sites', {}).items() %}
  14. {%- do valid_sites.append('{}{}'.format(id, apache.confext)) %}
  15. {%- endfor %}
  16. {# Take sites from apache.register_site #}
  17. {%- for id, site in salt['pillar.get']('apache:register-site', {}).items() %}
  18. {%- do valid_sites.append('{}{}'.format(site.name, apache.confext)) %}
  19. {%- endfor %}
  20. {%- if salt['file.directory_exists'](dirpath) %}
  21. {%- for filename in salt['file.readdir'](dirpath) %}
  22. {%- if filename not in valid_sites %}
  23. apache-config-vhosts-cleanup-{{ filename }}-cmd-run:
  24. cmd.run:
  25. - name: a2dissite {{ filename }} || true
  26. - onlyif: "test -L {{ dirpath }}/{{ filename }} || test -f {{ dirpath }}/{{ filename }}"
  27. - require_in:
  28. - module: apache-service-running-restart
  29. - module: apache-service-running-reload
  30. {%- endif %}
  31. {%- endfor %}
  32. {%- endif %}
  33. {%- endif %}{# Debian #}