Puppet

1. Genereal

  • Common commands
$ puppet help
$ puppet apply path/file.pp
$ puppet resource mailalias postmaster
$ facter
$ facter | grep version
$ facter | grep mb
$ facter | grep free
$ puppet facts 
$ puppet facts find
$ puppet facts --render-as yaml
$ facter --yaml
$ puppet facts --render-as json 
$ facter --json
$ puppet module search apache
  • Variables Start with $, must start with lowercase or underscore, and it only can contain numbers, letter and underscore.
$myvar $my_var $my3tupes    # Valid
$Myvar $my-var $3types      # Invalid
$_myvar                     # Should only used within local scope

# There are only String, Numeric, and Boolean
$ny_name = 'Jo'
$num_phone = 12342143214
$not_tre = false
$not_defined = undef
  • Varibales in strings Do not surround standalone variables with {} or quotes. That is only valid within a string.
$test='my-test'
$fact_uptime=$facts['uptime']
notify {'greeting':
  message => "heillo ${test} ${kernel} ${fact_uptime}"
}
  • puppetlabs libs

    • stdlib:
         include stdlib
         $nametype = type_of( $my_name )
      
  • Numbers

$decimal = 123
$decimal = 123.33
$octal = 0775
$hexadecimal = 0xFAFA
  • Arrays Convert an array in to a comma-separated list of values:
myfunction( *$array_of_arguments ){}

  • Hash
$homes={
  'key1'=>'value1', 
  'key2'=>'value2',
}
  • Functions
debug(message)
info(message)
notice(message)
warning(message)
err(message)
  • Ruby style
notice('haha')     ====    'haha'.notice()
  • No operation It validates, not apply, a manifest.
file { 'testfile':
  ensure => present,
  mode => '0700',
  replace => true,
  content => 'hie1111',
  path => '/nail/home/pparuni/test.log',
  noop => true,   # <---- This will not replace the file test.log
}

Testing

  • General
    • Test files usually end in _myvarspec.rb. Underscore_
    • Tests should be placed inside spec/classes
    • Definte type test should go inside spec/defines
    • Hosts tests should go inside spec/hosts
    • Function tests should go inside spec/functions

References

-Puppet Resource Types -Puppet Forge catalogue of modules