configure half cluster with different value

Our application TIER consist 50 servers managed by Ansible that need to be configured to speak with 2 backend servers.

/etc/app.cfg :

config_server={{ db_server_address }}

We need half of the cluster config to point to bd1.example.com and other half db2.example.com .

Any thoughts ?

many ways:

- since i normally have a counter on servers 'app01 -app04' you can do
a mod 2 on the server id and put one address or the other depending on
the result.

- you can run the mod2 vs the position of the server in the group it belongs in.

- you can create 2 groups and split the servers manually, each group
gets a diff db server assigned as config_server variable and use that
(in case you want to manually distribute them).

- use random assignment on each server, it should end up at a 50%
distribution, but it can be skewed, specially with small numbers.

- use mod2 on the last octet on the server IP (assumes even
distribution in the subnets).

etc

Thank you Brian.

I was able to use the random filter but I’m not able to use modulo… can you give me an example for your first two suggestions ?

Regards,
Nicolas.

I'll give you the first

in app.conf.j2:

{% for host in groups['cluster']%}
{% if loop.counter % 2 == 0 %}
{{ even hosts}}
{% else %}
{{ odd hosts}}
{% endif %}
{% endfor %}

the 2nd one is the same but just extracting the digits from the
hostname and using that instead of loop.counter