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.

60 line
1.7KB

  1. {% from "apache/map.jinja" import apache with context %}
  2. include:
  3. - apache
  4. {% for id, site in salt['pillar.get']('apache:sites', {}).items() %}
  5. {% set documentroot = site.get('DocumentRoot', '{0}/{1}'.format(apache.wwwdir, id)) %}
  6. {{ id }}:
  7. file:
  8. - managed
  9. - name: {{ apache.vhostdir }}/{{ id }}{{ apache.confext }}
  10. - source: {{ site.get('template_file', 'salt://apache/vhosts/standard.tmpl') }}
  11. - template: {{ site.get('template_engine', 'jinja') }}
  12. - context:
  13. id: {{ id|json }}
  14. site: {{ site|json }}
  15. map: {{ apache|json }}
  16. - require:
  17. - pkg: apache
  18. - watch_in:
  19. - module: apache-reload
  20. {% if site.get('DocumentRoot') != False %}
  21. {{ id }}-documentroot:
  22. file.directory:
  23. - unless: test -d {{ documentroot }}
  24. - name: {{ documentroot }}
  25. - makedirs: True
  26. {% if site.get('DocumentRootUser') %}
  27. - user: {{ site.DocumentRootUser }}
  28. {% endif %}
  29. {% if site.get('DocumentRootGroup') %}
  30. - group: {{ site.DocumentRootGroup }}
  31. {% endif %}
  32. - allow_symlink: True
  33. {% endif %}
  34. {% if grains.os_family == 'Debian' %}
  35. {% if site.get('enabled', True) %}
  36. a2ensite {{ id }}{{ apache.confext }}:
  37. cmd.run:
  38. - unless: test -f /etc/apache2/sites-enabled/{{ id }}{{ apache.confext }}
  39. - require:
  40. - file: /etc/apache2/sites-available/{{ id }}{{ apache.confext }}
  41. - watch_in:
  42. - module: apache-reload
  43. {% else %}
  44. a2dissite {{ id }}{{ apache.confext }}:
  45. cmd.run:
  46. - onlyif: test -f /etc/apache2/sites-enabled/{{ id }}{{ apache.confext }}
  47. - require:
  48. - file: /etc/apache2/sites-available/{{ id }}{{ apache.confext }}
  49. - watch_in:
  50. - module: apache-reload
  51. {% endif %}
  52. {% endif %}
  53. {% endfor %}