0% found this document useful (0 votes)
13 views

Puppet Code Review

The document provides an overview of Puppet including its architecture, resources, manifests, classes, modules, variables, templates, class parameters, and roles and profiles. It also describes labs that can be done to learn Puppet configuration management.

Uploaded by

paranomic8681
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Puppet Code Review

The document provides an overview of Puppet including its architecture, resources, manifests, classes, modules, variables, templates, class parameters, and roles and profiles. It also describes labs that can be done to learn Puppet configuration management.

Uploaded by

paranomic8681
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

OFFICIAL (CLOSED) \ NON-SENSITIVE

Introduction
OFFICIAL (CLOSED) \ NON-SENSITIVE

What is Puppet?

• Configuration management tool

• Idempotent
• Checks and only makes changes if required

• Puppet Code
• Based on Ruby language
OFFICIAL (CLOSED) \ NON-SENSITIVE

What is Puppet?

• Client-Server architecture
• Puppet Master
• Puppet Node (agent)

• Communicates over SSL


OFFICIAL (CLOSED) \ NON-SENSITIVE

Puppet Resources
OFFICIAL (CLOSED) \ NON-SENSITIVE

Puppet Resources

• Basic units that Puppet manages or interacts with

• Resource Types
• File
• Service
• Package
https://puppet.com/docs/puppet/latest/type.html

• Defined using parameters (attributes)


OFFICIAL (CLOSED) \ NON-SENSITIVE

Puppet Resources

• Defining a resource of file type


Syntax:
OFFICIAL (CLOSED) \ NON-SENSITIVE

Puppet Resources - Quiz

• Defining a resource of package type

• To ensure the httpd package is present on a system with the


version ‘2.4.6-45.el7.centos’.

How will the package be defined?


OFFICIAL (CLOSED) \ NON-SENSITIVE

Puppet Resources

• Defining a resource of package type

• To ensure the httpd package is present on a system with the


version ‘2.4.6-45.el7.centos’.

How will the package be defined?

2.4.6-45.el7.centos
OFFICIAL (CLOSED) \ NON-SENSITIVE

Manifests & Classes


OFFICIAL (CLOSED) \ NON-SENSITIVE

Manifests & Classes

• Resources
OFFICIAL (CLOSED) \ NON-SENSITIVE

Manifests & Classes

• Classes
• Collection of defined Puppet resources
• Contains variables and parameters

• Syntax:
OFFICIAL (CLOSED) \ NON-SENSITIVE

Manifests & Classes

• Puppet manifest
• File containing Puppet code
• .pp file extension

• Puppet code
• Evaluated and applied top-down
• Can be re-ordered using relationships

• Coding style
• Must use two-space soft tabs.
• Must not use literal tab characters.
https://puppet.com/docs/puppet/latest/style_guide.html
OFFICIAL (CLOSED) \ NON-SENSITIVE

Modules
OFFICIAL (CLOSED) \ NON-SENSITIVE

Modules

• Collection of related classes

• modulepath
• A list of directories that Puppet master checks for modules
puppet config print modulepath

• A directory structure that contains the manifests


OFFICIAL (CLOSED) \ NON-SENSITIVE

Modules

• init.pp
• Main class similar to the main() method in C/C++ and Java
• Contains a class name that corresponds with the module name
OFFICIAL (CLOSED) \ NON-SENSITIVE

Recap

Resources Classes Modules


• Basic building blocks • Collection of • Collection of classes
resources

• Defined using • Defines and configure • Defines and configures


parameters resources such as a specific technology
(attributes) files, packages,
services
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab environment

• Puppet Learning VM
• Self-contained environment
• Pre-installed with Puppet Enterprise

• Requirements
• Web browser e.g. Google Chrome
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab guide (http://<IP ADDRESS>)

• Personalization
Toggle Table of Content

Text size

Font

Color Scheme
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab 0 - Welcome

• Objectives
• Be familiar with the lab environment
• Learn how to use the Quest tool
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab 1 – Hello Puppet

• Objectives
• Explore Puppet resources
• Understand how resources are represented in Puppet codes

• quest begin hello_puppet

• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab 2 – Manifests & Classes

• Objectives
• Understand how Puppet manifest files are organized
• Create a module to manage 2 software package
• Validate Puppet codes using the parser tool

• quest begin manifests_and_classes

• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab 3 – Package, File, and Service

• Objectives
• Combine the use of resources to manage an application
• Be able to define dependencies among resources

• quest begin package_file_service

• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE

Variables
OFFICIAL (CLOSED) \ NON-SENSITIVE

Variables

• Replace hard-coded values

• Improve code readability and reduce errors

• Prefixed with a dollar sign ‘$’

• Value is assigned to a variable with an equal sign ‘=’


OFFICIAL (CLOSED) \ NON-SENSITIVE

Variables

• Value once assigned is fixed


• Cannot be modified or reassigned at run-time

• Variables must be defined before being used


OFFICIAL (CLOSED) \ NON-SENSITIVE

Templates
OFFICIAL (CLOSED) \ NON-SENSITIVE

Templates

• Replace hard-coded text files

• Text file with “dynamic” content defined using EPP tags


• Pass in variables at run-time using epp() function

• Embedded Puppet file


• .epp file extension
OFFICIAL (CLOSED) \ NON-SENSITIVE

Templates

• Usage: epp(‘module/template file’, ‘hash of values’)


OFFICIAL (CLOSED) \ NON-SENSITIVE

Templates

• pasture_config.yaml.epp /etc/pasture_config.yaml
OFFICIAL (CLOSED) \ NON-SENSITIVE

Class Parameters
OFFICIAL (CLOSED) \ NON-SENSITIVE

Class Parameters

• Comma-separated list

• Enclosed in parentheses ‘()’

• Optional
• Data type
• Default value
OFFICIAL (CLOSED) \ NON-SENSITIVE

Class Parameters

Variables Parameters
• Replace hard-coded values • Replaces hard-coded variables
• Assign values inside classes • Assign values at run-time
OFFICIAL (CLOSED) \ NON-SENSITIVE

Class Parameters

• Assigning values
• Treat the class like another resource

• Syntax:
OFFICIAL (CLOSED) \ NON-SENSITIVE

Class Parameters

• Example
OFFICIAL (CLOSED) \ NON-SENSITIVE

Roles & Profiles


OFFICIAL (CLOSED) \ NON-SENSITIVE

Roles & Profiles

Classes Modules Profiles Roles


• Collection of resources • Collection of classes • Collection of modules • Collection of profiles

• Defines and configure • Defines and configures • Defines and configures • Defines a desired state
resources such as files, a specific technology a technology stack for a system
packages, services
• file leaf • mod grass • profile::pasture • role::farm
• package soil • mod tree • profile::farm_animal
• service irrigation • mod sheep • profile::barn
• user farmer
OFFICIAL (CLOSED) \ NON-SENSITIVE

Roles & Profiles

Classes Modules Profiles Roles


• Collection of resources • Collection of classes • Collection of modules • Collection of profiles

• Defines and configure • Defines and configures • Defines and configures • Defines a desired state
resources such as files, a specific technology a technology stack for a system
packages, services
• package httpd • mod ssh::server • profile::base • role::prod_web_server
• file /etc/motd • mod syslog • profile::apache
• service httpd • mod apache • profile::monitoring
• mod zabbix • profile::security
• mod cis::apache_http
• mod cis::centos
OFFICIAL (CLOSED) \ NON-SENSITIVE

Roles & Profiles

• Role Role Role


• Contains only profiles
Profile Profile Profile Profile
Module Module Module Module
• Profile Class Class Class Class Class Class Class Class
• Contains modules
• Can include other profiles Module Module Profile Module
Module
Class Class Class Class Class Class
Class Class
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab 4 – Variables & Templates

• Objectives
• Use variables to replace hardcoded values
• Use templates to implement reusability of static files

• quest begin variables_and_templates

• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab 5 – Class Parameters

• Objectives
• Use parameters in classes to replace variables
• Understand the value of writing configurable classes

• quest begin class_parameters

• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE

Lab 6 – Roles & Profiles

• Objectives
• Understand the usage for roles and profiles

• quest begin roles_and_profiles

You might also like