Ticket ID #180 ‐ Create Node Resources and Develop Basic Module - GriffinKat/group-a GitHub Wiki
Creating a Puppet Module
- Step 1- Create the following directories, all under /etc/puppetlabs/code/modules on the management server.
-
-
Use the following command to get to the specified location:
cd /etc/puppetlabs/code/modules
-
-
-
Use the mkdir command to create the following directories:
sudo mkdir sudo
Within the sudo directory we will now create 3 subdirectories. Follow the commands below.
Use the
cd sudo
command to change directory.Use the following command to create the three subdirectories.
sudo mkdir {files,templates,manifests}
-
-
-
Now, we create the file sudo/manifests/init.pp. Every module must have this basic structure.
sudo touch manifests/init.pp
-
-
- Edit the init.pp file so that it contains the following:
class sudo { package { 'sudo': ensure => present, } file { '/etc/sudoers': owner => 'root', group => 'root', mode => '0440', source => 'puppet:///modules/sudo/etc/sudoers', require => Package['sudo'], } }
- Edit the init.pp file so that it contains the following:
-
-
Use the following command to edit the init.pp file and paste the above code.
sudo nano manifests/init.pp
-
-
-
Obtain a verified copy of your sudoers file and copy it to:
/etc/puppetlabs/code/modules/sudo/files/etc/sudoers
Use the command below to copy the sudoers file from /etc directory into the specified directory.
sudo cp /etc/sudoers /etc/puppetlabs/code/modules/sudo/files/etc/sudoers
NOTE: First make the /etc directory in the files directory. Use command
sudo mkdir -p /etc/puppetlabs/code/modules/sudo/files/etc
Verify that the file has been copied by running the command:
ls /etc/puppetlabs/code/modules/sudo/files/etc/
-
-
Troubleshooting done while applying configuration to node (Database server)
-
Syntax error in the site.pp file. The screenshot of the error while testing the configuration on node.
Troubleshooting steps- The include sudo directive was written in the package block, removed it from there.
-
Permission denied to read the sudoers file in the module.
Troubleshooting steps- Changed the ownership to the Puppet user and group using the following command and restarting the puppet server.
sudo chown -R puppet:puppet /etc/puppetlabs/code/modules/sudo/files/
sudo systemctl restart puppetserver
Screenshot of successful application of the module to the node