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.

66 lines
1.9KB

  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, site.get('ServerName', id))) %}
  6. apache_vhosts_{{ id }}:
  7. file.managed:
  8. - name: {{ apache.vhostdir }}/{{ id }}{{ apache.confext }}
  9. - source: {{ site.get('template_file', 'salt://apache/vhosts/standard.tmpl') }}
  10. - template: {{ site.get('template_engine', 'jinja') }}
  11. - context:
  12. id: {{ id|json }}
  13. site: {{ site|json }}
  14. map: {{ apache|json }}
  15. - require:
  16. - pkg: apache
  17. - watch_in:
  18. - module: apache-reload
  19. - require_in:
  20. - module: apache-restart
  21. - module: apache-reload
  22. - service: apache
  23. {% if site.get('DocumentRoot') != False %}
  24. {{ id }}-documentroot:
  25. file.directory:
  26. - name: {{ documentroot }}
  27. - makedirs: True
  28. - user: {{ site.get('DocumentRootUser', apache.get('document_root_user'))|json }}
  29. - group: {{ site.get('DocumentRootGroup', apache.get('document_root_group'))|json }}
  30. - allow_symlink: True
  31. {% endif %}
  32. {% if grains.os_family == 'Debian' %}
  33. {% if site.get('enabled', True) %}
  34. a2ensite {{ id }}{{ apache.confext }}:
  35. cmd.run:
  36. - unless: test -f /etc/apache2/sites-enabled/{{ id }}{{ apache.confext }}
  37. - require:
  38. - file: /etc/apache2/sites-available/{{ id }}{{ apache.confext }}
  39. - watch_in:
  40. - module: apache-reload
  41. - require_in:
  42. - module: apache-restart
  43. - module: apache-reload
  44. - service: apache
  45. {% else %}
  46. a2dissite {{ id }}{{ apache.confext }}:
  47. cmd.run:
  48. - onlyif: test -f /etc/apache2/sites-enabled/{{ id }}{{ apache.confext }}
  49. - require:
  50. - file: /etc/apache2/sites-available/{{ id }}{{ apache.confext }}
  51. - watch_in:
  52. - module: apache-reload
  53. - require_in:
  54. - module: apache-restart
  55. - module: apache-reload
  56. - service: apache
  57. {% endif %}
  58. {% endif %}
  59. {% endfor %}