diff --git a/haproxy/templates/haproxy.jinja b/haproxy/templates/haproxy.jinja index 129f118..ae35092 100644 --- a/haproxy/templates/haproxy.jinja +++ b/haproxy/templates/haproxy.jinja @@ -59,6 +59,21 @@ defaults errorfile {{ errorfile[0] }} {{ errorfile[1] }} {%- endfor %} {%- 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', {}) %} @@ -153,6 +168,11 @@ frontend {{ frontend[1].get('name', frontend[0]) }} bind {{ frontend[1].bind }} {%- endif %} {%- endif %} + {%- if 'options' in frontend[1] %} + {%- for option in frontend[1].options %} + {{ option }} + {%- endfor %} + {%- endif -%} {%- if 'redirects' in frontend[1] %} {%- for front_redirect in frontend[1].redirects %} redirect {{ front_redirect }} @@ -216,7 +236,7 @@ backend {{ backend[1].get('name',backend[0]) }} {%- endif %} {%- if 'servers' in backend[1] %} {%- 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 %} {% endif %} {%- endfor %} diff --git a/pillar.example b/pillar.example index 3aee2e1..1706398 100644 --- a/pillar.example +++ b/pillar.example @@ -47,6 +47,15 @@ haproxy: 503: /etc/haproxy/errors/503.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: stats: bind: @@ -146,3 +155,4 @@ haproxy: host: apiserver2.example.com port: 80 check: check + extra: resolvers local_dns resolve-prefer ipv4