apache-formula/apache/vhosts/standard.sls
Jonathan Ballet 42426f3f4a Don't fail on missing DocumentRoot
If the DocumentRoot value wasn't set, applying the state would cause the
following error:

          ID: site.example.com-documentroot
    Function: file.directory
        Name: None
      Result: False
     Comment: Specified file None is not an absolute path
     Started: 15:07:05.596723
    Duration: 4.929 ms
     Changes:

This fixes the problem by not trying to check for the DocumentRoot directory is
the value is missing.
2015-03-25 15:06:18 +01:00

43 lines
1.1 KiB
Plaintext

{% from "apache/map.jinja" import apache with context %}
include:
- apache
{% for id, site in salt['pillar.get']('apache:sites', {}).items() %}
{{ id }}:
file:
- managed
- name: {{ apache.vhostdir }}/{{ id }}{{ apache.confext }}
- source: {{ site.get('template_file', 'salt://apache/vhosts/standard.tmpl') }}
- template: {{ site.get('template_engine', 'jinja') }}
- context:
id: {{ id|json }}
site: {{ site|json }}
map: {{ apache|json }}
- require:
- pkg: apache
- watch_in:
- module: apache-reload
{% if 'DocumentRoot' in site %}
{{ id }}-documentroot:
file.directory:
- unless: test -d {{ site.get('DocumentRoot') }}
- name: {{ site.get('DocumentRoot') }}
- makedirs: True
{% endif %}
{% if grains.os_family == 'Debian' %}
a2ensite {{ id }}{{ apache.confext }}:
cmd:
- run
- unless: test -f /etc/apache2/sites-enabled/{{ id }}{{ apache.confext }}
- require:
- file: /etc/apache2/sites-available/{{ id }}{{ apache.confext }}
- watch_in:
- module: apache-reload
{% endif %}
{% endfor %}