# configure half cluster with different value

**URL:** <https://forum.ansible.com/t/configure-half-cluster-with-different-value/18624>\
**Category:** Ansible Project\
**Created:** [June 26, 2015, 6:37pm UTC](https://forum.ansible.com/t/configure-half-cluster-with-different-value/18624 "2015-06-26T18:37:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [June 26, 2015, 6:37pm UTC](https://forum.ansible.com/t/configure-half-cluster-with-different-value/18624/1 "2015-06-26T18:37:47Z")

</div>

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](http://bd1.example.com) and other half [db2.example.com](http://db2.example.com) .

Any thoughts ?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 26, 2015, 7:10pm UTC](https://forum.ansible.com/t/configure-half-cluster-with-different-value/18624/2 "2015-06-26T19:10:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [June 28, 2015, 9:29pm UTC](https://forum.ansible.com/t/configure-half-cluster-with-different-value/18624/3 "2015-06-28T21:29:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 2, 2015, 10:13pm UTC](https://forum.ansible.com/t/configure-half-cluster-with-different-value/18624/4 "2015-07-02T22:13:31Z")

</div>

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
