Puppet Agent Commands Cheat Sheet



Puppet agent post install tasks - configure agent, hostnames, and sign request EC2 Puppet master/agent basic tasks - main manifest with a file resource/module and immediate execution on an agent node Setting up puppet master and agent with simple scripts on EC2 / remote install from desktop EC2 Puppet - Install lamp with a manifest ('puppet apply'). If Agent Based Architecure is used, then an Agent exist at the remote amanged end. Another important difference is about the mechanism used by these Automation systems.If we check Ansible vs Puppet vs Chef, Ansible uses Push mechanism while Chef and Puppet use Pull mechanism.

Resources

  • Core Types Cheat Sheet from Puppet
  • Resource Type Reference from Puppet

Video Script

In this video, we will begin learning how to use Puppet to configure a system. Before creating our own Puppet scripts, called Manifest Files, we will discuss how Puppet actually views a system it is configuring.

In Puppet, a system is simply a set of resources. There are many different types of resources, such as files, user accounts, installed programs, and more. In addition to a type, each resource has a title, and a set of attributes giving additional information about the resource. The resources section below the video has links to the Puppet documentation for resource types.

Let’s review some different resources using the Puppet Learning VM. You can also perform many of these same operations on your Windows and Linux computers with Puppet Agent installed. If you’d like to follow along, I’ll be working in the hello_puppet quest on the Puppet Learning VM.

I have already performed the first task for the hello_puppet quest, so I’m now connected to one of the internal systems and installed the Puppet Agent on it. Now, I can start Task 2, where I review a file resource. Using Puppet, you can describe a file resource such as the following:

That should give you information about that file. Here you can see that the resource is of type file, and has its path for a title. Below that are the attributes of the file, given as parameter => value pairs. Since the file doesn’t exist, the only attribute visible is the ensure attribute, and it shows that the file is absent on the system.

We can easily create the file using this command:

Then we can use the same resource command to view it:

Now we can see many additional attributes of the file.

We can also use the puppet resource command to modify resource. For example, let’s add some content to that file:

Once you run that command, you can view the contents of the file to confirm that it worked:

There are many types of resources that can be viewed and modified in this way. For example, you can view information about a user account, such as the learning account on the current VM:

You can also find information about installed software packages, such as the Apache Webserver httpd:

In this case, since the package is not installed on the system, the ensure attribute is set to purged, which is similar to absent.

The Puppet Learning VM quest describes how to see the inner workings of a Puppet Resource by breaking it. I’m not going to go over that process in detail, but I recommend you review that information on your own.

As with the file, we can configure attributes easily enough:

That command will install the latest version of the httpd package. Note that when it executes, the ensure value is changed to the current version. Later, as you define your Puppet manifests, you can use the ensure attribute to install the latest version using the present value, or provide a specific version number here if desired.

There are many different types of resources available in Puppet. How to open dmg file in mac os x. I encourage you to review some of the documentation linked below this video before continuing, just to get an idea of what is available. The next video will describe how to create your own Puppet Manifest Files and apply them to a system directly using the Puppet Agent.

Facter

show all facters
facter
show OS Family facter
facter osfamily
show facters in YAML
facter -y
show facters in JSON
facter -j
get Puppet Enterprise version
facter -p | grep pe_
get Puppet agent All-in-one version
facter -p | grep aio
use fact inside a manifest using 'facter' function
notify { 'OS is ${::facts['operatingsystem']}': }
use fact inside manifest directly
notify { 'OS is $::operatingsystem': }
get facter Hash
facter system_uptime
{
days => 2,
hours => 70,
seconds => 253058,
uptime => '2 days' }

facter system_uptime.hours
70
get OS major release from manifest
$::operatingsystemmajrelease

MCollective

Run MCollective as 'peadmin'
sudo -i -u peadmin
check connection to nodes
mco ping

get nodes by Facter name
mco facts timezone
check how many MCO nodes are running
mco puppet count
restart apache service
mco rpc service restart service=httpd
check status of a package
mco package status puppet
list all subcollectives
mco inventory ––list-collectives

disable puppet agent on node
mco puppet disable -I nodename
find all nodes that are x64
mco ping -F architecture=x86_64
find all nodes containing NYC in hostname
mco find ––with-identity /nyc/

find all nodes with nginx class
mco find ––with-class nginx
kick off 'puppet agent -t' on your nodes
mco puppet runall -F osfamily=Redhat 5

this will run puppet agent -t on all nodes where
osfamily fact = redhat, 5 concurrent runs
kick off Puppet run on node 'abc.xyz'
mco puppet runonce -l abc.xyz
run command against a subcollective
mco ping -T us_collective
start/stop service on a node
mco service ntp start -I ny14.nyc

show all available MCO plugins
mco plugin doc
show last run statistics for all nodes
mco rpc puppet last_run_summary

mco client logs (on PE Master)
/var/lib/peadmin/.mcollective.d/client.log

Modules

print modulepath:
puppet config print modulepath

modules help:
puppet help module
search available modules: (PuppetForge)
puppet module search 'nginx'
install a module
Cheatpuppet module install author/module
build new module with full skeleton:
puppet module generate author/modulePuppet Agent Commands Cheat Sheet
list installed modules:
puppet module list

check for missing module dependenciesPuppet
puppet module list --tree
build a module release package (.tar.gz)
puppet module build author/module
show modified files of an installed module
puppet module changes
Module paths:
apache/ # main module dir
apache/manifests # manifest code
apache/lib # plugins, ruby code
apache/templates # ERB templates
apache/files # files used in module
apache/tests # usage examples
apache/Modulefile # metadatapaths inside a module:

content => template('mysql/my.cnf.erb'),

Template is in: $modulepath/mysql/templates/my.cnf.erb

source => 'puppet:///modules/mysql/my.cnf'

File is in: $modulepath/mysql/files/my.cnf

Augeas

Augeas binary tool
/opt/puppetlabs/puppet/bin/augtool
show all available lenses
augtool> ls /augeas/load/
set value in a file
augtool> set /files/etc/ssh/sshd_config/PermitrootLogin no
augtool> save
get specific data tree branch

cat /etc/hosts

127.0.0.1 puppetmaster localhost localhost.localdomain ::1 localhost localhost.localdomain localhost6
#managed nodes
192.168.237.148 host1
192.168.237.155 host2

augtool> ls /files/etc/hosts

1/ = (none)
2/ = (none) #comment = managed nodes
3/ = (none)
4/ = (none)

augtool> ls /files/etc/hosts/4

ipaddr = 192.168.237.155
canonical = host2
check Augeas version
ls /augeas/
root = /
context = /files
variables = (none)
version/ = 1.4.0
save = overwrite
span = disable
load/ = (none)
files/ = (none)

Augeas Help

Admin commands:
help - print help
load - (re)load files under /files
quit - exit the program
retrieve - transform tree into text
save - save all pending changes
store - parse text into tree
transform - add a file transform

Read commands:

dump -xml - print a subtree as XML
get - get the value of a node
label - get the label of a node
ls - list children of a node
match - print matches for a path expression
print - print a subtree
errors - show all errors encountered inprocessing files
span - print position in input filecorresponding to tree

Write commands:

clear - clear the value of a node
clearm - clear the value of multiple nodes
ins - insert new node
insert - insert new node (alias of 'ins')
mv - move a subtree
move - move a subtree (alias of 'mv')
cp - copy a subtree
copy - copy a subtree (alias of 'cp')
rename - rename a subtree label
rm - delete nodes and subtrees
set - set the value of a node
setm - set the value of multiple nodes
touch - create a new node
Augeas in manifest
or if making multiple changes to same file

Hiera

4 types of functions
hiera()
hiera_array()
hiera_hash()
hiera_include()
Hiera Array
$ hiera ssh_users['root', 'jeff', 'gary', 'hunter']
$ hiera ssh_users.0
root
Hiera Hash:
$ hiera user{'name'=>'kim', 'home'=>'/home/kim'}
$ hiera user.name
kim
use Hiera for class assignment in Site.pp
hiera_include()
Hiera config file
/etc/puppetlabs/puppet/hiera.yaml
Hierarchies:
---
:hierarchy:

- 'nodes/%{::clientcert}'
- 'roles/%{::role}'
- '%{::osfamily}'
- '%{::environment}'
- common
sample hiera xyz.yaml
---
### xyz
classes:
- apache
- apache::vhost
- ntp
owner: joe smith
location: new york
business_unit: billing
Get hiera value for this host:
hiera classes ::hostname=xyz ::environment=production
['apache', 'apache::vhost', 'ntp']
run Hiera in debug mode:
hiera classes ::hostname=xyz -d
Use Hiera in manifest:
$my_dns_servers = hiera('dns_servers')
or array:
$my_dns_servers = hiera_array('dns_servers')
get Hiera key value directly from command line
puppet apply -e 'notice(hiera('<KEY>'))'
dfdfPuppet agent commands cheat sheet printable
Log File locations:
https://docs.puppet.com/pe/latest/install_what_and_where.htmlPuppet Agent Commands Cheat Sheet

Puppet Agent Commands Cheat Sheet Pdf

Cron

run script every day at 12.30am
command => '/usr/bin/python myscript.py',
minute => '30',

Puppet Command Line

}

Puppet Commands

run script every tue at 5 am
command => '/usr/bin/python myscript.py',
minute => '0',
weekday => 'Tuesday'


Puppet Agent Commands

Troubleshooting

404 error, could not request certificate when running