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 in Puppet by Jayanth
23 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 by Sirajul
• 29,660 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 in Puppet by Sirajul
• 29,660 points
85 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 in Puppet by Sirajul
• 29,660 points
25 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 in Puppet by Sirajul
• 29,660 points
23 views
0 votes
0 answers
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
177 views
0 votes
1 answer
0 votes
1 answer
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 in Puppet by Sirajul
• 29,660 points
24 views