Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

Learn Puppet with Me – Day 2

49 sec read

Today we are going to learn about Puppet Modules.

What is Puppet Modules? Puppetlabs defines it as “Modules are self-contained bundles of code and data. You can write your own modules or you can download pre-built modules from the Puppet Forge.”Nearly all Puppet manifests belong in modules. The sole exception is the main site.pp manifest, which contains site-wide and node-specific code.

puppetlabs-memcache

Modules are how Puppet finds the classes and types it can use — it automatically loads any classor defined type stored in its modules.

Module Layout

On disk, a module is simply a directory tree with a specific, predictable structure:

  • <MODULE NAME>
    • manifests
    • files
    • templates
    • lib
    • facts.d
    • tests
    • spec

We will start with basic module and slowly move towards the complex module structure.

Let’s begin:

#mkdir modules/memcached
#mkdir modules/memcached/manifests
#mkdir modules/memcached/files
#vi nodes.pp

node ‘puppetagent1.cse.com’ {
include memcached
}
#define memcached class in the file init.pp
#vi modules/memcached/manifests/init.pp

class memcached {
package { ‘memcached’:
ensure => installed,
}

file { ‘/etc/memcached.conf’:
source => puppet:///modules/memcached/memcached.conf’,
owner => ‘root’,
group => ‘root’,
mode => ‘0644’,
require => Package[‘memcached’],
}

service { ‘memcached’:
ensure => running,
enable => true,
require => [Package[‘memcached’], File[ ‘/etc/memcached.conf’]]
}
}

That’s all. You can go ahead and run puppet agent -t on puppet client machine to get memcache ready.

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server