Now that we've had some exposure to the .epp
template format, let's finish the review::motd
class. If you've been using .epp
for a while, this will be familiar. If not, you might struggle a bit. Feel free to ask any questions needed or run through the docs page for a brush-up.
https://docs.puppet.com/puppet/latest/lang_template_epp.html
The exercise asks you to add some dynamic content to /etc/motd
with an .epp
template. For simplicity, we'll just use a few facts. If you'd rather use your own variables, remember that with .epp
, you must pass them in with the variables hash.
-
Make sure you are in your
review
modulecd $(puppet agent --configprint environmentpath)/production/modules/review
-
Edit the file
[modulepath]/review/manifests/motd.pp
. -
Add a file resource to manage
/etc/motd
using a template to generate the content. -
Edit the
[modulepath]/review/templates/motd.epp
template in thereview
module.- Add a brief welcome message, using the
fqdn
of the host and any other facts you'd like.
- Add a brief welcome message, using the
-
Deploy your codebase:
git init
git remote add origin [email protected]:puppet/review.git
git checkout -b studentN
git add .
git commit -m 'initial commit'
git push origin studentN
Go to your [control-repo] and edit the Puppetfile by uncommenting the following lines in [control-repo]/Puppetfile
. When you're done editing, push it to your branch.
cd ~/control-repo
mod 'review',
:git => '[email protected]:puppet/review.git',
:branch => 'studentN'
You could also use :branch => :control_branch
which is automatically populated with the control repos branch name (which matches your module repo branch name in this example).
-
Deploy your codebase.
git add --all
git commit -m "Add Review Module"
git push origin studentN
-
Add classification
-
Navigate to the CONFIGURE -> Classification tab.
-
Find and select your Node Group from the list.
studentN-env environment group
-
Add the
review
class and enter a username. -
Log into your agent node and enforce the configuration.
puppet agent -t
-
If your new classes don't show in the PE Console as expected, try validating their syntax using pdk validate
.
[root@training modules]# tree review/
review/
├── examples
│ ├── motd.pp
│ └── init.pp
├── files
│ └── bashrc
└── manifests
│ ├── motd.pp
│ └── init.pp
└── templates
└── motd.epp
# A description of what this class does
#
# @summary A short summary of the purpose of this class
#
# @example
# include review::motd
class review::motd {
file { '/etc/motd':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
content => epp('review/motd.epp'),
}
}
Welcome to <%= $fqdn %>.
This machine is managed with Puppet.
| Previous Lab | Next Lab |