A collection of task oriented solutions in Puppet

 

Manage global Yum configuration

Challenge

You want to manage the global Yum configuration

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)

Once the module is installed there are two ways to manage the configuration, as one large class invocation:

class yumconfig {

  class { 'yum':
    config_options => {
      gpgcheck    => true,
      debuglevel  => 5,
    },
  }

}

or as a collection of individual resources:

class yumconfig {

  yum::config { 'plugins':
    ensure => 0,
  }

}

Explanation

The core yumrepo type enables you to control per repository configuration settings but it does not allow you to control the global settings contained in /etc/yum.conf. To manage these you will need to install the puppet/yum module from puppetforge. Installing the module is done in the usual way:

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 you have the new yum class available you can choose to manage the global config in one big class declaration:

class yumconfig {

  class { 'yum':
    config_options => {
      gpgcheck    => true,
      debuglevel  => 5,
    },
  }

}

Or option by option, in a single, or across multiple, puppet classes:

class yumconfig {

  yum::config { 'plugins':
    ensure => 0,
  }

}

Or even a combination of the two:

class yumconfig {

  class { 'yum':
    config_options    => {
      gpgcheck    => true,
      debuglevel  => 5,
    },
  }

  yum::config { 'plugins':
    ensure => 0,
  }

}

If you want to completely remove an option from the global configuration file then you need to explicitly set it to absent.

class removeoption {

  yum::config { 'plugins':
    ensure => 'absent',
  }

}

See also