Puppet

What is Puppet?

Puppet is one of the most popular tools in DevOps ecosystem used for configuration management and deployment automation. It can perform tasks like creating users, installing packages and configuring servers based on a centralized configuration. It ensures the configurations, packages and services are same across several machines, thus being a powerful tool to automate configuration of similar environments.

Installation Steps

In this section we will show how to setup puppet in a client/server architecture having one puppet master and one puppet agent.

Installation on Master

Installation on Agent

Certificates

Important Concepts

Manifests

"Puppet programs are called manifests and they contain a set of instructions to be executed for building the infrastructure. Manifests are a collection of resource declarations and use the .pp extension."[1]

Example of manifest file which first updates apt-get and then installs mysql-server package and ensures mysql service is running[2] -

        exec { 'apt-get update':
            command => '/usr/bin/apt-get update'
        }
        package { 'mysql-server':
            require => Exec['apt-get update'],
            ensure => installed,
        }
        service { 'mysql':
            ensure => running,
        }
        

Resources

Puppet comes with a number of built-in resources which can be used as the components for building the infrastructure. Some of the most commonly used resource types are "files, services, packages and user."[1]
To know all the available resource types use this command [2]-

        puppet resource --types
        

Examples of using file resource -
Put below lines in your manifest file.

        file { 'infra.txt':
            path    => '/home/infra.txt',
            content => 'Starting to learn puppet'
        }
        

After applying the catalog on agent node the file infra.txt will be created at the given path with the provided content.

Modules

Modules are similar to packages having both code and data. They are good for code organization and need to defined in a particular directory structure. "Puppet loads the content of modules and automatically makes the classes, types and plug-ins available."[5]
Puppet has number of modules for specific purposes available here which can be downloaded and used directly. Some examples of modules are nginx, ntp, pip etc. The steps to install and use the module are provided on the particular module webpage like this for ntp.

Sources
  1. Writing Puppet Manifests
  2. Puppet Examples
  3. Puppet Tutorial By Alessandro Franceschi
  4. Puppet Tutorial
  5. Puppet Modules