Puppet Site Learning

first contact

start page http://docs.puppetlabs.com/learning/

steps:

  1. download vmware player for linux , the tutorial use vmware workstation or virtual box but I try vmware player and it's ok
  2. download the virtual machines
  3. login like root and password puppet at the console
  4. discover ip address
  5. login with webconsole 80 port

first operation from video of download page 4 minutes

save the information on root user in a file

puppet resource user root > root.pp

modify the information to change the shell
nano root.pp 
user { 'root':
  shell            => '/bin/sh',
}

apply the new settings
 puppet apply root.pp
Notice: Compiled catalog for learn.localdomain in environment production in 0.13 seconds
Notice: /Stage[main]//User[root]/shell: shell changed '/bin/bash' to '/bin/sh'
Notice: Finished catalog run in 0.33 seconds

change the config file with bash shell and simulate the apply
 puppet apply root.pp --noop
Notice: Compiled catalog for learn.localdomain in environment production in 0.28 seconds
Notice: /Stage[main]//User[root]/shell: current_value /bin/sh, should be /bin/bash (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.53 seconds

notice the words ''should be'' for the simulation command
if you apply a configuration file that not produce a change the output is like this
puppet apply root.pp 
Notice: Compiled catalog for learn.localdomain in environment production in 0.13 seconds
Notice: Finished catalog run in 0.25 seconds

Learning guide

ral

puppet describe -l — List all of the resource types available on the system.
puppet describe -s <TYPE> — Print short information about a type, without describing every attribute
puppet describe <TYPE> — Print long information, similar to what appears in the type reference.

inspect the user root type

puppet resource user root
user { 'root':
  ensure           => 'present',
  comment          => 'root',
  gid              => '0',
  home             => '/root',
  password         => '$1$jrm5tnjw$h8JJ9mCZLmJvIxvDLjw1M/',
  password_max_age => '99999',
  password_min_age => '0',
  shell            => '/bin/bash',
  uid              => '0',
}

create an user

 puppet resource user katie ensure=present shell="/bin/zsh" home="/home/katie" managehome=true
Notice: /User[katie]/ensure: created
user { 'katie':
  ensure => 'present',
  home   => '/home/katie',
  shell  => '/bin/zsh',
}

Learning Puppet — Manifests

script remove an user
write script

nano user-absent.pp
user {'katie':
      ensure => absent,
    }

execute script
puppet apply user-absent.pp
Notice: Compiled catalog for learn.localdomain in environment production in 0.13 seconds
Notice: /Stage[main]//User[katie]/ensure: removed
Notice: Finished catalog run in 0.33 seconds

create a test file

nano file1.pp
file {'testfile':
      path    => '/tmp/testfile',
      ensure  => present,
      mode    => 0640,
      content => "I'm a test file.",
    }

if we change the permission
chmod 777 /tmp/testfile

and after we execute the apply command again, the file come back to the manifest state
 puppet apply fil1.pp 
Notice: Compiled catalog for learn.localdomain in environment production in 0.11 seconds
Notice: /Stage[main]//File[testfile]/mode: mode changed '0777' to '0640'
Notice: Finished catalog run in 0.25 seconds
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License