A collection of task oriented solutions in Puppet

 

Install package group with Yum

Challenge

You want to install a group of packages via Yum

Solution

puppet module install puppet-yum

Notice: Downloading from https://forgeapi.puppet.com ...
/etc/puppetlabs/code/environments/production/modules
|--- puppet-yum (v2.2.1)
  |--- puppetlabs-concat (v4.2.1)
  |--- puppetlabs-stdlib (v4.25.1)

And once the module is installed

class yumgroup {

  # list the available groups with yum grouplist
  yum::group { 'Fedora Packager':
    ensure  => present,
    timeout => 300,
  }

}
Notice: /Stage[main]/Yumgroup/Yum::Group[Fedora Packager]
  /Exec[yum-groupinstall-Fedora Packager]/returns:
  executed successfully
$ yum group summary | grep Installed
Installed Groups: 1

$ yum group list | grep Installed -A 1
Installed Groups:
   Fedora Packager

Explanation

Yum based systems, such as CentOS and Fedora, offer a feature called package groups. These are collections of packages that serve a common purpose, for example 'System Tools' or 'Sound and Video'. Installing a package group installs all the packages it contains in a single command. This abstraction can be helpful if the exact packages to implement a groups function change between major operating system versions. You may not care exactly which packages are installed for example, as long as all of those required to build packages are present.

The functionality to manage groups of packages via yum is not contained in puppet core so we will need to install a puppet module before we begin.

puppet module install puppet-yum

Notice: Downloading from https://forgeapi.puppet.com ...
/etc/puppetlabs/code/environments/production/modules
|--- puppet-yum (v2.2.1)
  |--- puppetlabs-concat (v4.2.1)
  |--- puppetlabs-stdlib (v4.25.1)

Once the module is installed ensuring a package group is present via puppet is just a yum::group resource away.

class yumgroup {

  # list the available groups with yum grouplist
  yum::group { 'Fedora Packager':
    ensure  => present,
    timeout => 300,
  }

}
Notice: /Stage[main]/Yumgroup/Yum::Group[Fedora Packager]
  /Exec[yum-groupinstall-Fedora Packager]/returns:
  executed successfully

You can confirm puppet made the expected changes using the yum group subcommands. First we'll check a package group was installed by running yum group summary and then we'll confirm it's the one we wanted with yum group list | grep Installed -A 1

$ yum group summary | grep Installed
Installed Groups: 1

$ yum group list | grep Installed -A 1
Installed Groups:
   Fedora Packager

See also