We’re going to start off with a relatively simple review
module that should
manage a named user and some configuration files. We'll also manage a
file in a separate class.
First, we will add a single $user
parameter to define the username to manage. If
the user is root
, the path to the user’s home directory will have to change
to reflect that. Then we’ll add a class that will manage the /etc/motd
.
Since the catalog is compiled on the master, we'll need to use some logic to extrapolate the user’s home directory.
$homedir = $user ? {
'root' => '/root',
default => "/home/${user}",
}
For the rest of this course, we will refer to the /etc/puppetlabs/code/environments/production/modules
as [modulepath]
. You can find this again with running cd $(puppet agent --configprint environmentpath)/production/modules
and will be used for all labs.
We haven't explained to you how to do most of these tasks, so please request assistance from the instructor as needed.
-
Change directory to your
[modulepath]
by runningcd $(puppet agent --configprint environmentpath)/production/modules
-
Run this command:
pdk new module
-
You will see several questions requiring an answer. Enter these answers:
Replace the N in studentN with your student number (for example,
student8
).Question Answer Module Name review
Forge Name studentN
Credit author Student N
License Apache-2.0
Operating reviews RedHat
-
Navigate to your
review
directory.cd review
-
Create the class.
pdk new class review
-
Edit
manifests/init.pp
- Add a single parameter,
$user
, defaulting toreview
- Add a single parameter,
-
The class should manage:
- The
$user
user with a.bashrc
in their home directory. - Ensure that the
puppet
service is stopped. - Declare a class named
review::motd
.
- The
-
Create a class named
review::motd
in the proper location.pdk new class motd
-
Leave the body of the class blank. We'll finish it soon.
Expect an error from the following command.
-
Create your smoke test file to validate your work.
cd examples
-
Edit
examples/init.pp
-
Validate your syntax using
pdk
.pdk validate
-
Using puppet apply, validate your smoke test.
puppet apply examples/init.pp --noop
[root@training modules]# tree review/
review/
├── examples
│ ├── motd.pp
│ └── init.pp
├── files
│ └── bashrc
└── manifests
├── motd.pp
└── init.pp
class review::motd {
}
# A description of what this class does
#
# @summary A short summary of the purpose of this class
#
# @example
# include review
class review (
$user = 'review',
) {
include review::motd
$homedir = $user ? {
'root' => '/root',
default => "/home/${user}",
}
user { $user:
ensure => present,
shell => '/bin/bash',
managehome => true,
}
file { "${homedir}/.bashrc":
ensure => file,
owner => $user,
group => $user,
mode => '0644',
source => 'puppet:///modules/review/bashrc'
}
service { 'puppet':
ensure => stopped,
enable => false,
}
}
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
| Previous Lab | Next Lab |