Puppet-resources-sample-usage

1: Service:

service {

service_winbind_off:

name      => winbind,

ensure    => stopped,

enable => ‘false’,——————————————————-> it is for chkconfig off

schedule  => schedule_winbind_runlevels_off;

}

service {

service_winbind_on:

name      => winbind,

ensure    => running,

schedule  => schedule_winbind_runlevels;

}

2: Schedule:

schedule {

schedule_winbind_runlevels:

range     => “2 – 4”,

period    => daily,

repeat    => 1

}

schedule {

schedule_winbind_runlevels_off:

range     => “2 – 4”,

period    => daily,

repeat    => 1

}

schedule {
schedule_ezproxy_conf:
range       => “2 – 15”,
period      => hourly,
repeat      => 4,
}

3: Exec (executing a command):

exec {

winbind_runlevel:

command   => “/usr/sbin/sysv-rc-conf –level 2345 winbind on”, —-> it is also like chkconfig

logoutput => true,

path      => “/usr/sbin”,

schedule  => schedule_winbind_runlevels

}

exec {

winbind_runlevel:

command   => “/usr/sbin/sysv-rc-conf –level 2345 winbind off”,

logoutput => true,

path      => “/usr/sbin”,

schedule  => schedule_winbind_runlevels_off

}

4: File (file creation with content, file creation with source file, directory creation):

file { “/var/tmp/testfile”:

ensure => “present”,

owner => “root”,

group => “root”,

mode => “664”,

content => “This is a test file created using puppet.

Puppet is really cool”,

}

file {

“/etc/pam.d”:

ensure => directory,

}

file {

“/etc/pam.d/common-account”:

owner  => root,

group  => root,

mode   => 644,

require => File [“/etc/pam.d”],

source => “puppet://ldnfpi-slm01.xyz.com/files/ubuntu/etc/pam.d/common-account-no_winbind”,

}

5: Cron :

cron {

bucketclear:

ensure    => present,

command   => ‘find /var/lib/puppet/clientbucket -type f -mtime +7 -exec rm -f {} \;’,

user      => root,

hour      => 1,

minute    => 30,

}

cron {

redir_test_faculty:

command  => “/admin/apache/test_site_redir.sh -t facultytest.xyz.com -s  faculty.xyz.com”,

user     => root,

hour     => [10, 12, 14, 16, 18],

minute   => 5,

weekday  => [1,2,3,4,5],

}

cron {

reddot_www_welcome:

command  => “/admin/apache/add_doctype.sh /webdata/www.xyz.com/htdocs/theschool/welcome.htm > /dev/null 2>&1”,

user     => wwwsync,

hour     => ‘*’,

minute   => [12, 42],

}

6: Link (soft link creation):

file { ‘/etc/libnss-ldap.conf’:

ensure => ‘link’,

target => ‘/etc/ldap.conf’,

}

exec { testlamp_web_xml:

command   => “ln -s /etc/tomcat5.5/web.xml /var/lib/tomcat5.5/conf/web.xml”,

path      => “/bin:/usr/bin”,

logoutput => true

}

7: Package (Installation/removing):

class build_packages {

package { “build-essential”: ensure => “installed” }

}

class ldap_packages {

package { “openssh-server”: ensure => “installed” }

package { “libpam-ldap”: ensure => “installed” }

package { “nscd”: ensure => “installed” }

}

package {

nfs-common:

ensure   => installed,

provider => apt;

}

class snmpd_packages_absent {

package {

snmp:

ensure   => purged;

snmpd:

ensure   => purged;

}

package {

resolvconf:

ensure => absent,

}

8: User (user creation, password reset, ssh keys :

user {

“phinix”:

ensure     => present,

gid        => “users”,

uid        => “6352”,

membership => minimum,

shell      => “/bin/bash”,

home       => “/home/phinix”,

password   => ‘$1$phinix$9NqBVh0cSndbdMPmkkBPA0’,

comment    => “3rd-party service provider”,

}

class reset_root {

user { ‘root’:

ensure => present,

password => ‘$1$0zrpskqF$DcqufJlnWxGzdol4ixuPP0’,

}

file {

“/home/sscope”:

ensure   => directory,

schedule => ssh_authorised_keys_schedule_sscope;

“/home/sscope/.ssh”:

owner    => sscope,

group    => users,

mode     => 700,

ensure   => directory,

require  => File [“/home/sscope”],

schedule => ssh_authorised_keys_schedule_sscope;

“/home/sscope/.ssh/authorized_keys2”:

owner    => sscope,

group    => users,

mode     => 600,

source   => “puppet://server11.xyz.com/files/ubuntu/home/sscope/.ssh/authorized_keys2”,

schedule => ssh_authorised_keys_schedule_sscope;

}

Dependency link creation:-

class apache {

package { ‘httpd’:

ensure => ‘present’,

}

service {‘httpd’:

ensure => ‘running’,

require => Package[“httpd”],

}

}

In above example service will be started after package installation, this link created using a key word “require”.

file {

“/home/sscope”:

ensure   => directory,

file {    “/home/sscope/.ssh”:

owner    => sscope,

group    => users,

mode     => 700,

ensure   => directory,

require  => File [“/home/sscope”],

In the above example .ssh folder will be created after “/home/sscope” folder created. This link created using a key word “require”.