Puppet Code Review
Puppet Code Review
Introduction
OFFICIAL (CLOSED) \ NON-SENSITIVE
What is Puppet?
• 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)
Puppet Resources
OFFICIAL (CLOSED) \ NON-SENSITIVE
Puppet Resources
• Resource Types
• File
• Service
• Package
https://puppet.com/docs/puppet/latest/type.html
Puppet Resources
Puppet Resources
2.4.6-45.el7.centos
OFFICIAL (CLOSED) \ NON-SENSITIVE
• Resources
OFFICIAL (CLOSED) \ NON-SENSITIVE
• Classes
• Collection of defined Puppet resources
• Contains variables and parameters
• Syntax:
OFFICIAL (CLOSED) \ NON-SENSITIVE
• 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
• modulepath
• A list of directories that Puppet master checks for modules
puppet config print modulepath
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
Lab environment
• Puppet Learning VM
• Self-contained environment
• Pre-installed with Puppet Enterprise
• Requirements
• Web browser e.g. Google Chrome
OFFICIAL (CLOSED) \ NON-SENSITIVE
• 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
• Objectives
• Explore Puppet resources
• Understand how resources are represented in Puppet codes
• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE
• Objectives
• Understand how Puppet manifest files are organized
• Create a module to manage 2 software package
• Validate Puppet codes using the parser tool
• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE
• Objectives
• Combine the use of resources to manage an application
• Be able to define dependencies among resources
• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE
Variables
OFFICIAL (CLOSED) \ NON-SENSITIVE
Variables
Variables
Templates
OFFICIAL (CLOSED) \ NON-SENSITIVE
Templates
Templates
Templates
• pasture_config.yaml.epp /etc/pasture_config.yaml
OFFICIAL (CLOSED) \ NON-SENSITIVE
Class Parameters
OFFICIAL (CLOSED) \ NON-SENSITIVE
Class Parameters
• Comma-separated list
• 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
• 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
• 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
• Objectives
• Use variables to replace hardcoded values
• Use templates to implement reusability of static files
• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE
• Objectives
• Use parameters in classes to replace variables
• Understand the value of writing configurable classes
• Username: learning
• Password: puppet
OFFICIAL (CLOSED) \ NON-SENSITIVE
• Objectives
• Understand the usage for roles and profiles