Allow to configure several interfaces for a vhost.

This is done by split the interface pillar value instead of using a proper
list so it behaves exactly the same as before for simple 1 interface cases
(no need to refactor one's pillar files).

The resulting is something like:

  Listen 1.2.3.4:80
  Listen [2001🔤def💯:3]:80

  <VirtualHost 1.2.3.4:80 [2001🔤def💯:3]:80>
  ...
This commit is contained in:
David Douard 2016-01-25 12:19:55 +01:00
parent ef10de6a57
commit f01c72c637
4 changed files with 25 additions and 9 deletions

View File

@ -115,6 +115,16 @@ Example Pillar:
example.com: # must be unique; used as an ID declaration in Salt; also passed to the template context as {{ id }} example.com: # must be unique; used as an ID declaration in Salt; also passed to the template context as {{ id }}
template_file: salt://apache/vhosts/standard.tmpl template_file: salt://apache/vhosts/standard.tmpl
When using the provided templates, one can use a space separated list
of interfaces to bind to. For example, to bind both IPv4 and IPv6:
.. code:: yaml
apache:
sites:
example.com:
interface: '1.2.3.4 [2001:abc:def:100::3]'
``apache.manage_security`` ``apache.manage_security``
-------------------------- --------------------------

View File

@ -3,7 +3,7 @@
{% set sitename = site.get('ServerName', id) %} {% set sitename = site.get('ServerName', id) %}
{% set vals = { {% set vals = {
'interface': site.get('interface', '*'), 'interfaces': site.get('interface', '*').split(),
'port': site.get('port', '80'), 'port': site.get('port', '80'),
'ServerName': sitename, 'ServerName': sitename,
@ -22,9 +22,11 @@
'ProxyRoute': site.get('ProxyRoute', {}), 'ProxyRoute': site.get('ProxyRoute', {}),
} %} } %}
Listen {{ vals.interface }}:{{ vals.port }} {% for intf in vals.interfaces -%}
Listen {{ intf }}:{{ vals.port }}
{% endfor %}
<VirtualHost {{ vals.interface }}:{{ vals.port }}> <VirtualHost {%- for intf in vals.interfaces %} {{intf}}:{{ vals.port }}{% endfor -%}>
ServerName {{ vals.ServerName }} ServerName {{ vals.ServerName }}
{% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %} {% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %}

View File

@ -3,7 +3,7 @@
{% set sitename = site.get('ServerName', id) %} {% set sitename = site.get('ServerName', id) %}
{% set vals = { {% set vals = {
'interface': site.get('interface', '*'), 'interfaces': site.get('interface', '*').split(),
'port': site.get('port', '80'), 'port': site.get('port', '80'),
'ServerName': sitename, 'ServerName': sitename,
@ -23,9 +23,11 @@
} %} } %}
Listen {{ vals.interface }}:{{ vals.port }} {% for intf in vals.interfaces -%}
Listen {{ intf }}:{{ vals.port }}
{% endfor %}
<VirtualHost {{ vals.interface }}:{{ vals.port }}> <VirtualHost {%- for intf in vals.interfaces %} {{intf}}:{{ vals.port }}{% endfor -%}>
ServerName {{ vals.ServerName }} ServerName {{ vals.ServerName }}
{% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %} {% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %}

View File

@ -3,7 +3,7 @@
{% set sitename = site.get('ServerName', id) %} {% set sitename = site.get('ServerName', id) %}
{% set vals = { {% set vals = {
'interface': site.get('interface', '*'), 'interfaces': site.get('interface', '*').split(),
'port': site.get('port', '80'), 'port': site.get('port', '80'),
'ServerName': sitename, 'ServerName': sitename,
@ -38,9 +38,11 @@
}, },
} %} } %}
Listen {{ vals.interface }}:{{ vals.port }} {% for intf in vals.interfaces -%}
Listen {{ intf }}:{{ vals.port }}
{% endfor %}
<VirtualHost {{ vals.interface }}:{{ vals.port }}> <VirtualHost {%- for intf in vals.interfaces %} {{intf}}:{{ vals.port }}{% endfor -%}>
ServerName {{ vals.ServerName }} ServerName {{ vals.ServerName }}
{% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %} {% if site.get('ServerAlias') != False %}ServerAlias {{ vals.ServerAlias }}{% endif %}