Puppet code
Puppet code is composed primarily of resource declarations.
We can get the supported resource type by “puppet resource –types”
Resource declarations:
resource_type { ‘resource_name’
attribute => value

}

  • manifest(pp): Puppet programs
  • Classes: code blocks can be called in a code elsewhere, by include or class
    {‘example_class’:}
    It could have class inheritance, it is not OOP, just limited to few specific
    cases.
  • module: a collection of manifests and data(such as facts,files, and templates)
  • erb: teplate mixes with ruby code , like <% if @something -%> server <%=
    @server %> <% end -%>
    content => template(“${module_name}/xxx.erb”),

PuppetDB
It saves data generated by Puppet: nodes’ facts, catalogs and reports

Puppet File Bucket
Backup changed file

Hiera yaml
Hiera is Puppet’s builtin key/value data lookup system, which has some peculiar
characteristics:
It’s hierarchical: We can configure different hierarchies of data sources and these are traversed in order to find the value of the desired key, from the layer at the top, to the one at the bottom
It has a modular backend system: data can be stored on different places, according to the used plugins, from simple Yaml or Json files, to MongoDb, Mysql, PostgreSQL, Redis and others

version: 5

hierarchy:
  - name: "Eyaml hierarchy"
    lookup_key: eyaml_lookup_key         # Use eyaml backend. Note this can be specified for each level
    paths:                               # Instead of multiple hierarchy levels we can define just one with
      - "nodes/%{trusted.certname}.yaml" # multiple paths, when the same backend is used. It's exactly the same.
      - "role/%{::role}-%{::env}.yaml"
      - "role/%{::role}.yaml"
      - "common.yaml"
    options:                             # Hiera-eyaml specific options (the paths of the keypair used for encryption)
      pkcs7_private_key: /etc/puppetlabs/puppet/keys/private_key.pkcs7.pem
      pkcs7_public_key:  /etc/puppetlabs/puppet/keys/public_key.pkcs7.pem

defaults:
  datadir: data

Environment
codedir = /etc/puppetlabs/code
/etc/puppetlabs/code# ls
environments modules

server:
hiera.yaml: :datadir: /etc/puppetlabs/code/environments/%{::environment}/hiera
client:
puppet agent -t –environment beta

Facts
Puppet gathers facts about each of its nodes with a tool called facter. It
gathers information like os name, hostnames, ip address, ssh key and so on by
default, and will be used for filling in the template.

Catalog
When clients connect, the Puppet Master generates a catalog with the list of
the resources that clients have to apply locally.
It is the complete list of resources and their relationships.

MCollective
allows massively parallel actions on the server

Useful code

//code
before/notify/require/subscribe dependencies

// query Hiera for a given key
puppet lookup profiles

// puppet programe
puppet resource user root
puppet parser validate

//dbquery
puppet help query
puppet query facts ‘xxx’
//hiera
hiera dns_servers

// resource
puppet describe –list
puppet describe package –providers
puppet resource [name]

// masterless
puppet apply -l /tmp/manifest.log manifest.pp
puppet apply –modulepath /modules/ /manifests/file.pp
puppet apply –catalog catalog.json

// list configration
puppet master –configprint all
FACTER_operatingsystem=Debian puppet apply –noop admin/tests/init.pp

// agent
puppet agent –configprint all
puppet agent –configprint environment
puppet agent –test –verbose
puppet agent –test –debug/noop/waitforcert

//module
puppet module search apache
puppet module install puppetlabs-apache
sudo puppet module list
puppet config print modulepat
puppet help moduleh

//facter
sudo facter

refer