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.
      1. Use the following command to get to the specified location:

        cd /etc/puppetlabs/code/modules

        image

      1. Use the mkdir command to create the following directories:

        sudo mkdir sudo

        image

        Within the sudo directory we will now create 3 subdirectories. Follow the commands below.

        Use the cd sudo command to change directory.

        image

        Use the following command to create the three subdirectories.

        sudo mkdir {files,templates,manifests}

        image

      1. Now, we create the file sudo/manifests/init.pp. Every module must have this basic structure.

        sudo touch manifests/init.pp

        image

      1. 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'],
          }
        }
        
        
        
      1. Use the following command to edit the init.pp file and paste the above code.

        sudo nano manifests/init.pp

        image

      1. 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/

        image

Troubleshooting done while applying configuration to node (Database server)

  1. Syntax error in the site.pp file. The screenshot of the error while testing the configuration on node.

    image

    Troubleshooting steps- The include sudo directive was written in the package block, removed it from there.

    image

  2. Permission denied to read the sudoers file in the module.

    image

    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

    image

Screenshot of successful application of the module to the node

image