Puppet use Puppet templates to configure NTP

0 votes
How can i use puppet templates to configure ntp on my puppet server which is a ubuntu 18.04 machine?
Aug 9, 2019 in Puppet by Jayanth
499 views

1 answer to this question.

0 votes

Here's an example of configuring NTP using Puppet templates.

Directory should look like this:

/etc/puppet/modules/ntp/manifests
                       /templates

/etc/puppet/modules/ntp/manifests/init.pp (portion defining the template):

$ntp_server_suffix = ".ubuntu.pool.ntp.org"
file { '/etc/ntp.conf':
    content => template('ntp/ntp.conf.erb'),
    owner   => root,
    group   => root,
    mode    => 644,
}

 /etc/puppet/modules/ntp/templates/ntp.conf.erb:

driftfile /var/lib/ntp/drift
<% [1,2].each do |n| -%>
server <%=n-%><%=@ntp_server_suffix%>
<% end -%>
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1

When run with puppet this will result in an /etc/ntp.conf that looks like:

driftfile /var/lib/ntp/drift
server 1.ubuntu.pool.ntp.org
server 2.ubuntu.pool.ntp.org
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1

The key concepts that you need to keep in mind:

  • Variables defined in the puppet manifest (such as $ntp_server_suffix can be accessed as instance variables (@ntp_server_suffix) in the template

  • Loops and other ruby code can be used in erb templates

  • Code between <% and %> is executed by ruby

  • Code between <%= and %> is executed and output by ruby

  • Code between <%= and -%> is executed and output by ruby and the trailing newline character is suppressed.

Hope this helps!

answered Aug 9, 2019 by Sirajul
• 59,230 points

Related Questions In Puppet

0 votes
1 answer

How to install and configure r10k in puppet?

In order to get the latest version, ...READ MORE

answered Jul 29, 2019 in Puppet by Sirajul
• 59,230 points
3,414 views
0 votes
1 answer

Does puppet forge have modules that i can use to Install LAMP stack?

Puppet forge has modules for installing and ...READ MORE

answered Jul 30, 2019 in Puppet by Sirajul
• 59,230 points
661 views
0 votes
1 answer

Puppet: Error when trying to use many manifests

Your kp::testfile is a defined type, not ...READ MORE

answered Aug 7, 2019 in Puppet by Sirajul
• 59,230 points
513 views
0 votes
0 answers
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,520 views
+2 votes
1 answer
0 votes
1 answer

Puppet+Docker: How do i configure my docker container to use a NFS volume?

docker_volume { 'nfs-volume': ensure => ...READ MORE

answered Aug 13, 2019 in Puppet by Sirajul
• 59,230 points
536 views
0 votes
1 answer

Puppet+Docker: How do i configure my docker container to use a NFS volume through a Hiera config file?

If using Hiera, configure the docker::volumes class in the ...READ MORE

answered Aug 14, 2019 in Puppet by Sirajul
• 59,230 points
734 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP