How to install and configure r10k tool and validate puppet setup

Last updated on May 27 2022
Sarika Tak

Table of Contents

How to install and configure r10k tool and validate puppet setup

Puppet – Installing and Configuring r10K

In Puppet, we have a code management tool known as r10k that helps in managing environment configurations related to different kind of environments that we can configure in Puppet such as development, testing, and production. This helps in storing environment-related configuration in the source code repository. Using the source control repo branches, r10k creates environments on Puppet master machine installs and updates environment using modules present in the repo.

Gem file can be used to install r10k on any machine but for modularity and in order to get the latest version, we will use rpm and rpm package manager. Following is an example for the same.

$ urlgrabber -o /etc/yum.repos.d/timhughes-r10k-epel-6.repo

https://copr.fedoraproject.org/coprs/timhughes/yum -y install rubygem-r10k

Configure environment in /etc/puppet/puppet.conf

[main]

environmentpath = $confdir/environments

Create a Configuration File for r10k Config

cat <<EOF >/etc/r10k.yaml

# The location to use for storing cached Git repos

:cachedir: ‘/var/cache/r10k’

# A list of git repositories to create

:sources:

# This will clone the git repository and instantiate an environment per

# branch in /etc/puppet/environments

:opstree:

#remote: ‘https://github.com/fullstack-puppet/fullstackpuppet-environment.git’

remote: ‘/var/lib/git/fullstackpuppet-environment.git’

basedir: ‘/etc/puppet/environments’

EOF

Installing Puppet Manifest and Module

r10k deploy environment -pv

As we need to continue updating the environment in every 15 minutes, we will create a cron job for the same.

cat << EOF > /etc/cron.d/r10k.conf

SHELL = /bin/bash

PATH = /sbin:/bin:/usr/sbin:/usr/bin

H/15 * * * * root r10k deploy environment -p

EOF

Testing Installation

In order to test if everything works as accepted, one needs to compile the Puppet manifest for Puppet module. Run the following command and get a YAML output as the result.

curl –cert /etc/puppet/ssl/certs/puppet.corp.guest.pem \

–key /etc/puppet/ssl/private_keys/puppet.corp.guest.pem \

–cacert /etc/puppet/ssl/ca/ca_crt.pem \

-H ‘Accept: yaml’ \

https://puppet.corp.guest:8140/production/catalog/puppet.corp.guest

Puppet – Validating Puppet Setup

In Puppet, the setup can be tested locally. Hence, once we have set up Puppet master and node, it’s time to validate the setup locally. We need to have Vagrant and Vagrant box installed locally, which helps in testing the setup locally.

Setting Up the Virtual Machine

As we are testing the setup locally, we do not actually require a running Puppet master. This means without actually running the Puppet master on the server, we can simply use Puppet to apply command for Puppet setup validation. Puppet apply command will apply changes from local/etc/puppet depending on the virtual machine’s hostname in the configuration file.

First step which we need to perform in order to test the setup is to build the following Vagrantfile and start a machine and mount the /etc/puppet folder into place. All the files which are required will be place inside the version control system with the following structure.

Directory Structure

– manifests

\- site.pp

– modules

\- your modules

– test

\- update-puppet.sh

\- Vagrantfile

– puppet.conf

Vagrant File

# -*- mode: ruby -*-

# vi: set ft = ruby :

Vagrant.configure(“2”) do |config|

config.vm.box = “precise32”

config.vm.box_url = “http://files.vagrantup.com/precise64.box”

config.vm.provider :virtualbox do |vb|

vb.customize [“modifyvm”, :id, “–memory”, 1028, “–cpus”, 2]

end

 

# Mount our repo onto /etc/puppet

config.vm.synced_folder “../”, “/etc/puppet”

 

# Run our Puppet shell script

config.vm.provision “shell” do |s|

s.path = “update-puppet.sh”

end

 

config.vm.hostname = “localdev.example.com”

end

In the above code, we have used Shell provisioner in which we are trying to run a Shell script named update-puppet.sh. The script is present in the same directory where the Vagrant file is located and the content of the script are listed below.

!/bin/bash

echo “Puppet version is $(puppet –version)”

if [ $( puppet –version) != “3.4.1” ]; then

echo “Updating puppet”

apt-get install –yes lsb-release

DISTRIB_CODENAME = $(lsb_release –codename –short)

DEB = “puppetlabs-release-${DISTRIB_CODENAME}.deb”

DEB_PROVIDES=”/etc/apt/sources.list.d/puppetlabs.list”

 

if [ ! -e $DEB_PROVIDES ]

then

wget -q http://apt.puppetlabs.com/$DEB

sudo dpkg -i $DEB

fi

sudo apt-get update

sudo apt-get install -o Dpkg::Options:: = “–force-confold”

–force-yes -y puppet

else

echo “Puppet is up to date!”

fi

Further processing, the user needs to create a manifest file inside Manifests directory with the name site.pp which will install some software on VM.

node ‘brclelocal03.brcl.com’ {

package { [‘vim’,’git’] :

ensure => latest

}

}

echo “Running puppet”

sudo puppet apply /etc/puppet/manifests/site.pp

Once the user has the above script ready with the required Vagrant file configuration, the user can cd to the test directory and run the vagrant up command. This will boot a new VM, Later, install Puppet and then run it using the Shell script.

Following will be the output.

Notice: Compiled catalog for localdev.example.com in environment production in 0.09 seconds

Notice: /Stage[main]/Main/Node[brclelocal03.brcl.com]/Package[git]/ensure: created

Notice: /Stage[main]/Main/Node[brcllocal03.brcl.com]/Package[vim]/ensure: ensure changed ‘purged’ to ‘latest’

Validating Multiple Machine Configuration

If we need to test the configuration of multiple machines locally, it can be simply done by making a change in Vagrant configuration file.

New Configured Vagrant File

config.vm.define “brclelocal003” do |brclelocal003|

brclelocal03.vm.hostname = “brclelocal003.brcl.com”

end

 

config.vm.define “production” do |production|

production.vm.hostname = “brcleprod004.brcl.com”

end

Let’s assume we have a new production server, which needs SSL utility installed. We just need to extend the old manifest with the following configuration.

node ‘brcleprod004.brcl.com’ inherits ‘brcleloacl003.brcl.com’ {

package { [‘SSL’] :

ensure => latest

}

}

After making configurational changes in the manifest file, we just need to move to the test directory and run the basic vagrant up command which will bring up both brclelocal003.brcl.com and brcleprod004.brcl.com machine. In our case, we are trying to bring up production machine which could be done by running the vagrant up production command. The will create a new machine with the name production as defined in Vagrant file and it will have SSL package installed in it.

So, this brings us to the end of blog. This Tecklearn ‘How to install and configure r10k tool and validate puppet setup’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Puppet and build a career in DevOps domain, then check out our interactive, Continuous Deployment: Configuration Management using Puppet Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/continuous-deployment-configuration-management-using-puppet/

Continuous Deployment: Configuration Management using Puppet Training

About the Course

Tecklearn has specially designed this Continuous Deployment: Configuration Management using Puppet Training Course to advance your skills for a successful career in this domain. The course will cover different components of Git and GitHub and how they are used in software development operations. The course consists of Configuration Management using Puppet, Puppet Components, important concepts like Puppet Lifecycle, Puppet Language and Puppet Installation. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Puppet.

Why Should you take Configuration Management using Puppet Training?

  • Average salary of Puppet Professional is $90k – Payscale.com
  • Uber, Salesforce, PayPal, Booking.com, MIT, Starbucks. & Many other MNC’s worldwide use Puppet across industries.
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Continuous Deployment: Configuration Management using Puppet

  • Need of Configuration Management
  • What is Puppet
  • Puppet Architecture
  • Puppet Components
  • Puppet Lifecycle
  • Setting up Master Slave using Puppet
  • Puppet Manifests
  • Puppet Modules
  • Applying configuration using Puppet
  • Puppet File Server
  • Hands On

 

0 responses on "How to install and configure r10k tool and validate puppet setup"

Leave a Message

Your email address will not be published. Required fields are marked *