diff --git a/haproxy/templates/haproxy.jinja b/haproxy/templates/haproxy.jinja index 77ff51d..094d1aa 100644 --- a/haproxy/templates/haproxy.jinja +++ b/haproxy/templates/haproxy.jinja @@ -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 %} @@ -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 %}