# Best way to differentiate configurations

**URL:** <https://forum.ansible.com/t/best-way-to-differentiate-configurations/25061>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 23, 2017, 9:30pm UTC](https://forum.ansible.com/t/best-way-to-differentiate-configurations/25061 "2017-07-23T21:30:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Ankerstal](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@Peter\_Ankerstal](https://forum.ansible.com/u/Peter_Ankerstal)\
**Post date:** [July 23, 2017, 9:30pm UTC](https://forum.ansible.com/t/best-way-to-differentiate-configurations/25061/1 "2017-07-23T21:30:56Z")

</div>

Hi!

I pretty new to ansible and I have tried to read the docs on how to best differentiate configurations.

Everything seems very clean if every server have a _very_ specific purpose like “dbserver” or something. But Im having a hard time to figure this out in my pretty small environment of 10 machines where the servers have several roles.

**One example could be my NTP setup:**

I have ~10 server managed by ansible. Half of them live in aws ec2 and half in my home. Now, I would like to configure NTP on all these servers in a sensible and effective way.

The amazon servers I would like to have different “ntp servers” for different availability zones or sites.

Locally I have one GPS enabled NTP server which is the “master”.

- I want this “master” to peer with one or two other ntp-servers at home.
- This means I need different configs for every peer and aslo the master.

I also have several machines that would just just use the “master” and its peers as servers.

This gives me 7-10 different NTP configurations and Im not sure how to use roles, groups, variables and templates to differentiate these configs.

I would be very happy to receive suggestions on how to manage this kind of setup with ansible.

Thanks!

/Peter.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [July 24, 2017, 10:46pm UTC](https://forum.ansible.com/t/best-way-to-differentiate-configurations/25061/2 "2017-07-24T22:46:06Z")

</div>

Try to group things by common properties.  
Create a role that deploys ntpd, and use those common properties to  
construct a configuration file using a jinja2 template. That's in  
general the approach I take.  
When I found my templates getting crazy complex, it sometimes meant my  
infrastructure was in fact too complex.

I think you can get away with three types of configs:

1. the GPS based master server  
2. the machines that use the master and each other to peer with: 'peers'  
3. clients that use all/any of the above

You can then define a few groups

[ntp-servers]  
master  
peer1  
peer2  
peer3  
peer4

[slaves]  
ec2-a  
ec2-b  
ec2-c  
ec3-d

You can then define a var that contains the list of all the ntp-server  
except the one that the host in question:

&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;peers: "{{ groups['ntp-server'] | difference(inventory\_hostname) }}"

Set up a template task:

&nbsp;&nbsp;- name: ntpd config file  
&nbsp;&nbsp;&nbsp;&nbsp;template:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/ntp.conf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: ntp.conf.j2

Where the template looks like for the ntp-servers:

# Use all NTP peers except myself ({{ inventory\_hostname }})  
{% for peer in peers %}  
server {{ hostvars[peer]['ansible\_fqdn'] }}  
{% endfor %}

Regarding the Amazon specific settings, it's probably easiest to use a  
group variable that holds a list of NTP servers, based on the  
ec2\_region var.

There are many ways to expand this.

BTW - what do you mean by "Locally I have one GPS enabled NTP server"?  
If that means that it sits at your home, and you want your ec2  
instances to source their clock from it, then that's defeating the  
purpose of cloud infrastructure I think...

Dick
