Merge pull request #17 from sitepoint/resolvers_support

Add support for a resolvers section (new to 1.6).
This commit is contained in:
puneet kandhari 2015-08-05 11:10:45 -05:00
commit 5583754072
2 changed files with 31 additions and 1 deletions

View file

@ -59,6 +59,21 @@ defaults
errorfile {{ errorfile[0] }} {{ errorfile[1] }} errorfile {{ errorfile[0] }} {{ errorfile[1] }}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}
{%- if salt['pillar.get']('haproxy:resolvers') %}
#------------------
# DNS resolvers
#------------------
{%- for resolver in salt['pillar.get']('haproxy:resolvers', {}).iteritems() %}
resolvers {{ resolver[0] }}
{%- if 'options' in resolver[1] %}
{%- for option in resolver[1].options %}
{{ option }}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if 'listens' in salt['pillar.get']('haproxy', {}) %} {%- if 'listens' in salt['pillar.get']('haproxy', {}) %}
@ -153,6 +168,11 @@ frontend {{ frontend[1].get('name', frontend[0]) }}
bind {{ frontend[1].bind }} bind {{ frontend[1].bind }}
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{%- if 'options' in frontend[1] %}
{%- for option in frontend[1].options %}
{{ option }}
{%- endfor %}
{%- endif -%}
{%- if 'redirects' in frontend[1] %} {%- if 'redirects' in frontend[1] %}
{%- for front_redirect in frontend[1].redirects %} {%- for front_redirect in frontend[1].redirects %}
redirect {{ front_redirect }} redirect {{ front_redirect }}
@ -216,7 +236,7 @@ backend {{ backend[1].get('name',backend[0]) }}
{%- endif %} {%- endif %}
{%- if 'servers' in backend[1] %} {%- if 'servers' in backend[1] %}
{%- for server in backend[1].servers.iteritems() %} {%- for server in backend[1].servers.iteritems() %}
server {{ server[1].get('name',server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }} server {{ server[1].get('name',server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }} {{ server[1].get('extra', '') }}
{%- endfor %} {%- endfor %}
{% endif %} {% endif %}
{%- endfor %} {%- endfor %}

View file

@ -47,6 +47,15 @@ haproxy:
503: /etc/haproxy/errors/503.http 503: /etc/haproxy/errors/503.http
504: /etc/haproxy/errors/504.http 504: /etc/haproxy/errors/504.http
{# Suported by HAProxy 1.6 #}
resolvers:
local_dns:
options:
- nameserver resolvconf 127.0.0.1:53
- resolve_retries 3
- timeout retry 1s
- hold valid 10s
listens: listens:
stats: stats:
bind: bind:
@ -146,3 +155,4 @@ haproxy:
host: apiserver2.example.com host: apiserver2.example.com
port: 80 port: 80
check: check check: check
extra: resolvers local_dns resolve-prefer ipv4