Skip to content

Instantly share code, notes, and snippets.

@rjsalts
rjsalts / distribute.j2
Last active January 3, 2016 07:39
Equally divide servers to backends in ansible template
{% for host in groups['systems-server'] %}
{% if host == ansible_fqdn %}
{% set target_sysdb = loop.index0 % groups['sysdb-server']|length()|int() %}
{{ groups['sysdb-server'][target_sysdb] }}
{% endif %}
{% endfor %}