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.

84 lines
2.9KB

  1. # -*- coding: utf-8 -*-
  2. # vim: ft=sls
  3. {%- set tplroot = tpldir.split('/')[0] %}
  4. {%- set sls_package_install = tplroot ~ '.package.install' %}
  5. {%- set sls_service_running = tplroot ~ '.service.running' %}
  6. {%- from tplroot ~ "/map.jinja" import apache with context %}
  7. {#- The apache variable can grow _very_ large, especially the sites subkey.
  8. Create a trimmed copy with config variables. #}
  9. {%- set map = apache %}
  10. {%- do map.pop('sites', None) %}
  11. include:
  12. - {{ sls_package_install }}
  13. - {{ sls_service_running }}
  14. {%- for id, site in salt['pillar.get']('apache:sites', {}).items() %}
  15. {%- set documentroot = site.get('DocumentRoot', '{0}/{1}'.format(apache.wwwdir, site.get('ServerName', id))) %}
  16. apache-config-vhosts-standard-{{ id }}:
  17. file.managed:
  18. - name: {{ apache.vhostdir }}/{{ id }}{{ apache.confext }}
  19. - source: {{ site.get('template_file', 'salt://apache/config/vhosts/standard.tmpl') }}
  20. - template: {{ apache.get('template_engine', 'jinja') }}
  21. - makedirs: True
  22. - context:
  23. id: {{ id|json }}
  24. site: {{ site|json }}
  25. map: {{ map|json }}
  26. - require:
  27. - pkg: apache-package-install-pkg-installed
  28. - watch_in:
  29. - module: apache-service-running-reload
  30. - require_in:
  31. - module: apache-service-running-restart
  32. - module: apache-service-running-reload
  33. - service: apache-service-running
  34. {%- if site.get('DocumentRoot') != False %}
  35. apache-config-vhosts-standard-{{ id }}-docroot:
  36. file.directory:
  37. - name: {{ documentroot }}
  38. - makedirs: True
  39. - user: {{ site.get('DocumentRootUser', apache.get('document_root_user'))|json or apache.user }}
  40. - group: {{ site.get('DocumentRootGroup', apache.get('document_root_group'))|json or apache.group }}
  41. - allow_symlink: True
  42. {%- endif %}
  43. {%- if grains.os_family == 'Debian' %}
  44. {%- if site.get('enabled', True) %}
  45. apache-config-vhosts-standard-{{ id }}-cmd-run-a2en:
  46. cmd.run:
  47. - name: a2ensite {{ id }}{{ apache.confext }}
  48. - unless: test -f /etc/apache2/sites-enabled/{{ id }}{{ apache.confext }}
  49. - require:
  50. - file: apache-config-vhosts-standard-{{ id }}
  51. - watch_in:
  52. - module: apache-service-running-reload
  53. - require_in:
  54. - module: apache-service-running-restart
  55. - module: apache-service-running-reload
  56. - service: apache-service-running
  57. {%- else %}
  58. apache-config-vhosts-standard-{{ id }}-cmd-run-a2dis:
  59. cmd.run:
  60. - name: a2dissite {{ id }}{{ apache.confext }}
  61. - onlyif: test -f /etc/apache2/sites-enabled/{{ id }}{{ apache.confext }}
  62. - require:
  63. - file: apache-config-vhosts-standard-{{ id }}
  64. - watch_in:
  65. - module: apache-service-running-reload
  66. - require_in:
  67. - module: apache-service-running-restart
  68. - module: apache-service-running-reload
  69. - service: apache-service-running
  70. {%- endif %}
  71. {%- endif %} {# Debian #}
  72. {%- endfor %}