Ask Your Question

Puppet agent should pick DNS and NTP servers based on location

asked 2015-09-11 17:12:15 -0600

srianirudh gravatar image

We have 3 different Datacenters in our infrastructure. I am using puppetlabs/ntp module and saz/resolvconf and using hierainclude('classes') to install these 2 modules to all agents added to puppet.

Now my common.yaml file looks like this :

classes: ['ntp', 'resolv_conf']
        - datacenter1 NTP server
        - datacenter2 NTP server
        - datacenter3 NTP server
        - datacenter1 DNS server
        - datacenter2 DNS server
        - datacenter3 DNS server

So my puppet agent in Datacenter 3 gets all 3 datacenters's NTP server and DNS server.

But i would like it to have just pick NTP server and DNS server based on its location.

Like if my puppet agent is in Datacenter 1 then, use NTP and DNS servers from Datacenter 1. How can i define that in my common.yaml ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-09-12 04:46:39 -0600


Don't define it to your common.yaml.

Instead, create a fact to get to know on which DC you are (you can do that according to the IP or the hostnames rules).

Then add this fact to your Hiera hierarchy.

Finally, create a yaml for each DC where you will enter your NTP and DNS info.

In other words, let suppose your new fact will be called DC_location, you will enter

- "%{::DC_location}"
- common

to your hiera.yaml.

Finally, you will create files DC1.yaml, DC2.yaml and DC3.yaml in your hiera data location.


edit flag offensive delete link more

answered 2015-09-14 19:43:29 -0600

srianirudh gravatar image

updated 2015-09-14 21:23:44 -0600

Thanks for pointing me to the right direction. I wrote a custom ruby code to collect the datacenter location based on IP address and works like charm!!!

Can i have 2 facts in my hiera.yaml like this one below ?

- "%{::DC_location}" and "%{::domain}"
- common

Appreciate your help!!

edit flag offensive delete link more


Hi, no, you can't

ryayon gravatar imageryayon ( 2015-09-15 03:00:40 -0600 )edit

You can if you use - "%{::DC_location}"/"%{::domain}"

Richard Berwald gravatar imageRichard Berwald ( 2015-09-16 03:32:48 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-09-11 17:12:15 -0600

Seen: 258 times

Last updated: Sep 14 '15