A collection of task oriented solutions in Puppet

 

Add a Yum repository client config

Challenge

You want to configure yum to use a repository.

Solution

class basic_yum_repo {

  # configure the repo we want to use
  yumrepo { 'company_app_repo':
    enabled  => 1,
    descr    => 'Local repo holding company application packages',
    baseurl  => 'http://repos.example.org/apps',
    gpgcheck => 0,
  }

}

once this puppet code has run you can inspect the config -

cat /etc/yum.repos.d/company_app_repo.repo

[company_app_repo]
name=Local repo holding company application packages
baseurl=http://repos.example.org/apps
enabled=1
gpgcheck=0

Explanation

When using RPM/Yum/DNF based systems you'll often want to install packages from non-standard upstream repositories. In puppet this can be achieved using the built in yumrepo type. There are a tremendous number of options supported in repo configuration files and while the above example is a very simplified one it's worth reading through the types documentation, and the yum.conf manpage, linked to in the 'See Also' section to view all the possibilities.

Once you've configured a new yumrepo you'll often want to install packages from it. Don't forget to add a require attribute to any package resource that depends on your newly managed repos.

class package_requires {

  package { 'local_app':
    ensure  => 'installed',
    require => Yumrepo['company_app_repo'],
  }

}

See Also