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
- sudo su -
- apt-get update or yum update
- Install the Puppet Server package:
apt-get install puppetserver or yum install puppetserver - Start the Puppet Server service:
service puppetserver start or systemctl start puppetserver
Installation on Agent
- sudo su -
- apt-get update or yum update
- Install the Puppet Agent package:
apt-get install puppet-agent or yum install puppet-agent - Start the Puppet service:
/opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
Certificates
- On Puppet Agent run:
puppet agent --test - On Puppet Master view certificate requests:
puppet cert list - On the Puppet master sign the certificate request:
puppet cert sign <NAME>
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.