Hi folks,

you don’t like pages and pages of scripts, me neither … So please reduce your Puppet manifest as short as possible !

Take this example :

[root@puppetserver example]# cat ugly_manifest.pp
class ugly_manifest {
  package { 'bind-utils':
    ensure => present,
  }
  package { 'net-tools':
    ensure => present,
  }
  package { 'tcpdump':
    ensure => present,
  }
  if ! defined(Package['tree']) {
    package { 'tree':
    ensure => present,
    }
  }
  package { 'unwanted':
    ensure => absent,
  }
}

include ::ugly_manifest

Ok, it works, but it’s really too long ! So many lines to just install 4 RPMs !

You could do the same job in a shorter way :

[root@puppetserver example]# cat nice_manifest.pp
class nice_manifest {

# global attributes for resources :
  Package { ensure => present, }
# ---------------------------------

## install "netstat" ; "ifconfig" and "tcpdump" network utilities :
  package { [ 'bind-utils' , 'net-tools' , 'tcpdump' ]: }

## we can install "tree" utilities if not already done in another manifest :
  if ! defined(Package['tree']) {
    package { 'tree':
    }
  }

## uninstall "unwanted" package :
  package { 'unwanted':
    ensure => absent,
  }

}

include ::nice_manifest

Of course, it works :

[root@puppetserver example]# puppet parser validate nice_manifest.pp
[root@puppetserver example]# puppet apply nice_manifest.pp
Notice: Compiled catalog for puppetserver.argonay.wou in environment production in 0.92 seconds
Notice: /Stage[main]/Nice_manifest/Package[bind-utils]/ensure: created
Notice: /Stage[main]/Nice_manifest/Package[tcpdump]/ensure: created
Notice: /Stage[main]/Nice_manifest/Package[tree]/ensure: created
Notice: Applied catalog in 9.90 seconds

 

 

 

 

PDF24    Send article as PDF   

Leave a Reply

Your email address will not be published. Required fields are marked *


*