Adding Listeners, Multiple (optional) Binds per Listener/frontend

This commit is contained in:
Troy Germain 2015-07-17 19:00:32 -07:00
parent c351a70e00
commit 0275485194
2 changed files with 91 additions and 2 deletions

View File

@ -51,7 +51,67 @@ defaults
{% endif %}
#---------------------------------------------------------------------
# listen instances
#---------------------------------------------------------------------
{%- if 'listens' in salt['pillar.get']('haproxy', {}) %}
{%- for listener in salt['pillar.get']('haproxy:listens', {}).iteritems() %}
listen {{ listener[1].get(name, listener[0]) }}
{%- if 'bind' in listener[1] %}
{%- for socket in listener[1].bind %}
bind {{ socket }}
{%- endfor %}
{%- endif %}
{%- if 'redirects' in listener[1] %}
{%- for front_redirect in listener[1].redirects %}
redirect {{ front_redirect }}
{% endfor %}
{%- endif %}
{%- if 'acls' in listener[1] %}
{%- for acl in listener[1].acls %}
acl {{ acl }}
{%- endfor %}
{%- endif %}
{%- if 'reqadd' in listener[1] %}
{%- for reqadd in listener[1].reqadd %}
reqadd {{ reqadd }}
{%- endfor %}
{%- endif %}
{%-if 'default_backend' in listener[1] -%}
default_backend {{ listener[1].default_backend }}
{%- endif %}
{%-if 'use_backends' in listener[1] -%}
{%- for use_backend in listener[1].use_backends %}
use_backend {{ use_backend }}
{% endfor %}
{%- endif %}
{%- if 'balance' in listener[1] %}
balance {{ listener[1].balance }}
{%- endif %}
{%- if 'options' in listener[1] %}
{%- for option in listener[1].options %}
option {{ option }}
{%- endfor %}
{%- endif %}
{%- if 'cookie' in listener[1] %}
cookie {{ listener[1].cookie }}
{%- endif %}
{%- if 'stats' in listener[1] %}
{%- for option, value in listener[1].stats.iteritems() %}
{%- if option == 'enable' and value %}
stats enable
{%- else %}
stats {{ option }} {{ value }}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if 'servers' in listener[1] %}
{%- for server in listener[1].servers.iteritems() %}
server {{ server[1].get(name,server[0]) }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
#---------------------------------------------------------------------
# frontend instances
@ -59,7 +119,11 @@ defaults
{%- if 'frontends' in salt['pillar.get']('haproxy', {}) %}
{%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %}
frontend {{ frontend[1].get(name, frontend[0]) }}
bind {{ frontend[1].bind }}
{%- if 'bind' in frontend[1] %}
{%- for socket in frontend[1].bind %}
bind {{ socket }}
{%- endfor %}
{%- endif %}
{%- if 'redirects' in frontend[1] %}
{%- for front_redirect in frontend[1].redirects %}
redirect {{ front_redirect }}

View File

@ -44,6 +44,31 @@ haproxy:
503: /etc/haproxy/errors/503.http
504: /etc/haproxy/errors/504.http
listens:
stats:
bind:
- "0.0.0.0:8998"
mode: http
stats:
enable: True
uri: "/admin?stats"
refresh: "20s"
myservice:
bind:
- "*:8888"
options:
- forwardfor
- http-server-close
servers:
web1:
host: web1.example.com
port: 80
check: check
web2:
host: web2.example.com
port: 18888
check: check
frontends:
frontend1:
name: www-http