| {%- from "haproxy/map.jinja" import proxy with context %} |
| {%- from "linux/map.jinja" import network with context -%} |
| doc: |
| name: HAProxy |
| description: The Reliable, High Performance TCP/HTTP Load Balancer. |
| role: |
| proxy: |
| name: proxy |
| param: |
| version: |
| value: "{{ salt['cmd.run']('haproxy -v')|replace("HA-Proxy version ", '') }}" |
| endpoint: |
| {%- for listen_name, listen in proxy.get('listen', {}).iteritems() %} |
| {%- if listen.get('check', True) %} |
| {%- if listen.binds.0.address in ["0.0.0.0", "*", "\*"] %} |
| {% if grains.ipv4[0] == '127.0.0.1' %}{% set address = grains.ipv4[1] %}{% else %}{% set address = grains.ipv4[0] %}{% endif %} |
| {%- else %} |
| {%- set address = listen.binds.0.address %} |
| {%- endif %} |
| {{ listen_name }}_{{ listen.type|default(listen.get('mode', 'tcp')) }}: |
| name: {{ listen_name }} |
| {%- if listen.type is defined %} |
| type: {{ listen.type }} |
| {%- else %} |
| mode: {{ listen.mode|default('tcp') }} |
| {%- endif %} |
| {%- if listen.get('type', 'default') in ['general-service', 'openstack-service', 'http', 'contrail-api', 'admin'] %} |
| {%- if listen.type|default(None) in ['general-service', 'openstack-service', 'http', 'contrail-api', 'admin'] or listen.mode|default('tcp') == 'http' %} |
| address: "http://{{ listen.binds.0.address }}:{{ listen.binds.0.port }}/" |
| protocol: http |
| {%- else %} |
| address: "{{ listen.binds.0.address }}:{{ listen.binds.0.port }}" |
| protocol: tcp |
| {%- endif %} |
| {%- endif %} |
| {%- endif %} |
| {%- endfor %} |