Skip to content

Commit

Permalink
Initial attempt supporting fetching servers via pillars
Browse files Browse the repository at this point in the history
  • Loading branch information
darix committed Mar 11, 2022
1 parent 33f4d7e commit 84e37f3
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion haproxy/templates/haproxy.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,42 @@ listen {{ listener.get('name', listener_name) }}
{%- if 'servers' in listener %}
{%- for server_name, server in listener.servers|dictsort %}
{%- set name = server.get('name', server_name) %}
{%- if 'host' in server %}
server {{ name }} {{ server.host }}{% if 'port' in server %}:{{ server.port }}{% endif %} {% if 'maxconn' in server %} maxconn {{ server.maxconn }}{% endif %} {{ server.get('check', '') }} {{ server.get('extra', '') }}
{%- else %}
{%- for minion_id, entry in salt['mine.get'](mine_match, mine_target, tgt_type='compound')|dictsort() %}
{%- options=[] %}

{%- set mine_name = name ~ loop.index %}

{%- if not('extra' in server and 'weight' in server.extra) %}
{%- if 'mine_max_weight' in server %}

{%- set weight = server.mine_max_weight %}

{%- if 'mine_scale_weight' in server and server.mine_scale_weight %}
{%- set weight = server.mine_scale_weight - loop.index %}
#/if mine_scale_weight
{%- endif %}

{%- do options.append("weight " ~ weight) %}

{%- if 'mine_setbackup' in server and server.mine_setbackup and not('extra' in server and 'backup' in server.extra) %}
{%- do.option("backup") %}
#/ if mine_setbackup
{%- endif %}

#/ if mine_max_weight
{%- endif %}

#/ if extra and weight
{%- endif %}
server {{ name }} {{ server.host }}{% if 'port' in server %}:{{ server.port }}{% endif %} {% if 'maxconn' in server %} maxconn {{ server.maxconn }}{% endif %} {{ server.get('check', '') }} {{ server.get('extra', '') }} {{ options|join(' ') }}
#/ for saltmine
{%- endfor %}

#/ if host
{%- endif %}
{%- endfor %}
{%- endif %}
{% endfor %}
Expand Down Expand Up @@ -628,8 +663,45 @@ backend {{ backend.get('name', backend_name) }}
{%- endif %}
{%- if 'servers' in backend %}
{%- for server_name, server in backend.servers|dictsort %}
server {{ server.get('name', server_name) }} {{ server.host }}{% if 'port' in server %}:{{ server.port }}{% endif %} {{ server.get('check', '') }} {{ server.get('extra', '') }}
{%- set name = server.get('name', server_name) %}
{%- if 'host' in server %}
server {{ name }} {{ server.host }}{% if 'port' in server %}:{{ server.port }}{% endif %} {% if 'maxconn' in server %} maxconn {{ server.maxconn }}{% endif %} {{ server.get('check', '') }} {{ server.get('extra', '') }}
{%- else %}
{%- for minion_id, entry in salt['mine.get'](mine_match, mine_target, tgt_type='compound')|dictsort() %}
{%- options=[] %}

{%- set mine_name = name ~ loop.index %}

{%- if not('extra' in server and 'weight' in server.extra) %}
{%- if 'mine_max_weight' in server %}

{%- set weight = server.mine_max_weight %}

{%- if 'mine_scale_weight' in server and server.mine_scale_weight %}
{%- set weight = server.mine_scale_weight - loop.index %}
#/if mine_scale_weight
{%- endif %}

{%- do options.append("weight " ~ weight) %}

{%- if 'mine_setbackup' in server and server.mine_setbackup and not('extra' in server and 'backup' in server.extra) %}
{%- do.option("backup") %}
#/ if mine_setbackup
{%- endif %}

#/ if mine_max_weight
{%- endif %}

#/ if extra and weight
{%- endif %}
server {{ name }} {{ server.host }}{% if 'port' in server %}:{{ server.port }}{% endif %} {% if 'maxconn' in server %} maxconn {{ server.maxconn }}{% endif %} {{ server.get('check', '') }} {{ server.get('extra', '') }} {{ options|join(' ') }}
#/ for saltmine
{%- endfor %}

#/ if host
{%- endif %}
{%- endfor %}

{%- endif %}
{% endfor %}
{%- endif %}

0 comments on commit 84e37f3

Please sign in to comment.