Help with NTP module provided by puppetlabs

185 views
Skip to first unread message

Eddie Mashayev

unread,
Aug 9, 2015, 10:25:53 AM8/9/15
to Puppet Users
Hi All,

I have many servers spread in 3 different time zones USA (NY and San Francisco) and also in ISR. Have 3 NTP servers, one NTP server in each location.
https://forge.puppetlabs.com/puppetlabs/ntp module is letting you to insert an array of NTP servers

class { '::ntp':
servers => [ 'ntp1.corp.com', 'ntp2.corp.com' ],
}

I can override this array but the problem is how to fit the correct NTP server to each server in the different location.
In other words, how can I modified the puppet module to fit server to the correct NTP Server by locations.

For example - I thought using the server prefix name to choose the right NTP server, for example if this server is located in NY so it prefix name is ny-{server name} so I can fit it to NY NTP server but it look like a headache to do it.

Do you have any idea how can it be done in most efficient way with the NTP module provided by puppetlabs.


Thanks,
EddieM

Martin Alfke

unread,
Aug 9, 2015, 10:35:07 AM8/9/15
to puppet...@googlegroups.com
Hi Eddie,
Several solutions:

1. write wrapper module per data center:

class ny_ntp {
class { ‘::ntp’:
server => [‘ny_ntp.corp.com’],
}
}

class sf_ntp {
class { ‘::ntp’:
servers => [‘sf_ntp.corp.com’],
}
}

class isr_ntp {
class { ‘::ntp’:
servers => [‘isr_ntp.corp.com’],
}
}

use one of the the wrapper class within node classification

2. use hiera

provide a custom fact to identify location per server and put ntp::servers into the appropriate hiera data hierarchy.

Best,
Martin


>
>
> Thanks,
> EddieM
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/8cdf1ae0-46c8-4de6-bb06-9f42bdbd31ed%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Eddie Mashayev

unread,
Aug 10, 2015, 3:54:34 AM8/10/15
to Puppet Users
Hi Martin,

Thanks for the help. I used the second approach. 

1) I’ve created custom fact to identify the server location (I’m using the timezone fact) – Now I’m able to identify all my servers by location.
2) I’m not sure about the second part “put ntp::servers into the appropriate hiera data hierarchy” – I’m using Foreman and NOT Puppet enterprise if it matters. Can you elaborate more how to implement it right, maybe add some code if possible.

Thanks,
EddieM

Martin Alfke

unread,
Aug 10, 2015, 4:13:14 AM8/10/15
to puppet...@googlegroups.com

On 10 Aug 2015, at 09:54, Eddie Mashayev <eddi...@gmail.com> wrote:

> Hi Martin,
>
> Thanks for the help. I used the second approach.
>
> 1) I’ve created custom fact to identify the server location (I’m using the timezone fact) – Now I’m able to identify all my servers by location.
> 2) I’m not sure about the second part “put ntp::servers into the appropriate hiera data hierarchy” – I’m using Foreman and NOT Puppet enterprise if it matters. Can you elaborate more how to implement it right, maybe add some code if possible.

Hiera is not related to Puppet Enterprise.
Hiera is a data backend for automatic parameter lookups.
see http://docs.puppetlabs.com/hiera/latest/

You need to create a hiera.yaml config file.
The config file may look like this:

:backends:
- yaml
:yaml:
:datadir: ‘/etc/puppet/data’
:hierachy:
- “nodes/#{::certname}”
- “location/#{::timezone}”
- global

In your hiera data directory you can provide yaml files for hierarchies (you don’t have to, but you can!)

/etc/puppet/data/
- nodes/foo.bar.domain.com.yaml # has host specific parameters
- location/CEST.yaml # has parameters for CEST timezone
- location/PDT.yaml # has parameters for PDT timezone systems
- global.yaml # has global parameters

Hiera parses the data hierarchy and uses the first match.
To allow dynamic data lookup the variable names from the module have to be prefixed with the class name where they are used.
Note: this only works with parameterised classes, not with normal variables inside a manifest.

With foreman you should also be able to create a group setting based on timezone fact (I don’t have access to foreman right now, so I can not verify).

Best,
Martin
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d7398ad5-9b31-42e5-b3ee-d1eb889a8356%40googlegroups.com.

Richard Gray

unread,
Aug 10, 2015, 6:24:48 PM8/10/15
to puppet...@googlegroups.com


On 10/08/15 20:12, Martin Alfke wrote:
You need to create a hiera.yaml config file.
The config file may look like this:

:backends:
  - yaml
:yaml:
  :datadir: ‘/etc/puppet/data’
:hierachy:
  - “nodes/#{::certname}”
  - “location/#{::timezone}”
  - global


Further to Martin's comment, you may be interested to know that the Foreman location and environment are available to Hiera, so you might prefer to use those rather than the timezone fact. E.g.
:backends:
  - yaml
:yaml:
  :datadir: ‘/etc/puppet/data’
:hierachy:
  - “nodes/#{::certname}”
  - “location/#{::location}”
  - global
--

Richard Gray | Senior Operations Engineer
DDI: +64 9 950 2196 Fax: +64 9 302 0518
Mobile: +64 21 050 8178 Freephone:0800 SMX SMX (769 769)
SMX Limited: Level 15, 19 Victoria Street West, Auckland, New Zealand
Web: http://smxemail.com
SMX |
            Cloud Email Hosting & Security

This email has been filtered by SMX. For more information visit smxemail.com.

Eddie Mashayev

unread,
Aug 11, 2015, 11:12:58 AM8/11/15
to Puppet Users, richar...@smxemail.com
Thanks for the help :)

Eddie Mashayev

unread,
Aug 17, 2015, 3:17:43 AM8/17/15
to Puppet Users, richar...@smxemail.com
Hi Richard,

Just wondering, I do have now a locations configured on my Foreman (:locations_enabled: true), how can I access this data?
For example if I have a Facter variable named $location or $os_version so I can use it on mypuppet scripts. How can I use Foreman locations variable?
Hope I made myself clear :)


Thanks,

EddieM

Richard Gray

unread,
Aug 17, 2015, 5:58:28 PM8/17/15
to puppet...@googlegroups.com
Hi,

If you have Foreman configured as an ENC, the location parameter will be available to Hiera as a fact. e.g. In the master section of puppet.conf, you'll have something like (node.rb comes from Foreman):

external_nodes = /etc/puppet/node.rb

Then in hiera.yaml you can reference the location fact with #{::location}. Parameters such as location are passed to puppet from an ENC through the hash structure described at https://docs.puppetlabs.com/guides/external_nodes.html#enc-output-format

Cheers,
Richard
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages