Automating with Puppet: Standardizing NTP

Editor's Note: This post is a taste of what you'll get in our ebook about about automating routine IT tasks with Puppet, The Top 5 Things to Automate with Puppet Right Now. Download it for free to read the rest.

NTP is usually configured when a server is installed and never touched again. As such, it’s unlikely the NTP configurations are consistent across all servers in the infrastructure. Time discrepancies between servers can cause strange failures and it can be difficult to track down the root cause.

The NTP module takes care of that problem. Using the NTP module, all your servers will have consistent settings. If you need to change a time server, you simply update the Puppet code and you’re done.

Standardizing NTP across your entire environment is very easy with Puppet. Simply add the NTP module and its dependencies to your puppetfile:

mod 'puppetlabs/stdlib', '4.12.0'

mod 'puppetlabs/ntp',    '4.2.0'

Then use the NTP module inside your base SOE like so:

class profile::base {

  include ::ntp

  # This is left over from Task 1
  accounts::user { 'monitoring':
    ensure     => present,
    uid        => '450',
    gid        => '450',
    managehome => false,
    locked     => true,
  }

}

This will set up NTP on all your systems in its default state. If you would like to change the way it is configured, simply pass parameters to the ntp class. Here is a common example of managing NTP with custom servers:

class profile::base {

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

  # This is left over from Task 1
  accounts::user { 'monitoring':
    ensure     => present,
    uid        => '450',
    gid        => '450',
    managehome => false,
    locked     => true,
  }

}

Because this is part of the base profile that we created in Task 1, and every role includes the base profile, it will get applied to every server without us needing to change anything.

And that’s it, you’ve successfully standardized NTP across your infrastructure with Puppet. Watch this space for the rest of our series to learn about other common processes you can automate with Puppet.

Learn more

Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.