Part three of my little blog series “Cfengine 3 vs Puppet” shows several ways of how new packages can be installed with Puppet. Writing the Puppet manifest for installing new packages # There are multiple possibilities here, 3 of them are shown here # Possibility #1 # package { "slapd": ensure => "installed" } # […]

Author:

Part three of my little blog series “Cfengine 3 vs Puppet” shows several ways of how new packages can be installed with Puppet.

Writing the Puppet manifest for installing new packages

# There are multiple possibilities here, 3 of them are shown here
# Possibility #1
# package { "slapd":            ensure  => "installed" }
# package { "ldap-utils":       ensure  => "installed" }


# Possibility #2
# Package {                     ensure => "installed" }
# package { "slapd": }
# package { "ldap-utils": }


# Possiblity #3
 $packagesToBeInstalled = [ "slapd", "ldap-utils" ]
 package { $packagesToBeInstalled:      ensure => "installed" 

I saved the Puppet code snippet above as /etc/puppet/xenuser_org-003-ensure_packages_are_installed.pp and ran it with…

puppet apply xenuser_org-003-ensure_packages_are_installed.pp
warning: Could not retrieve fact fqdn
notice: /Stage[main]//Package[slapd]/ensure: created
notice: /Stage[main]//Package[ldap-utils]/ensure: ensure changed 'purged' to 'present'
notice: Finished catalog run in 18.09 seconds

On my Linux Mint box I can verify that these packages got installed with…

dpkg -l |grep slapd
ii  slapd                                  2.4.25-1.1ubuntu4.1                     OpenLDAP server (slapd)
dpkg -l |grep ldap-utils
ii  ldap-utils                             2.4.25-1.1ubuntu4.1                     OpenLDAP utilities

Some words on the code
One link I found showed me that there are several ways of installing packages with Puppet. The most simple and straight forward way is this one:

package { "slapd":            ensure  => "installed" }
package { "ldap-utils":       ensure  => "installed" }

The second possibility of installing new packages could be this one:

Package {                     ensure => "installed" }
package { "slapd": }
package { "ldap-utils": }

I think it is not 100% self-explaining, but still easy to adapt to your needs.
Another way, similar to the one I used in the Cfengine 3 snippet:

$packagesToBeInstalled = [ "slapd", "ldap-utils" ]
package { $packagesToBeInstalled:      ensure => "installed" }

I like this way the most. You first define an array containing the packages to be installed and then use the array in the “package” method. Awesome!

Summary
Again I am surprised in a positive way; the Puppet code is even shorter than the Cfengine 3 code snippet, but still performing the same task.

As usual you can download today’s Puppet manifest here.

Comments on this entry (no comments)

Did you like this post? You can share your opinion with us! Simply click here.

Add Your Comment

Powered by sweetCaptcha



seven − = 2