Adding a yum repo to puppet before doing anything else

Solution 1:

If you want to make sure a repository is installed on all your server then I would suggest something like this

node default {
   include base
}

class base {
   yumrepo { "IUS":
      baseurl => "http://dl.iuscommunity.org/pub/ius/stable/$operatingsystem/$operatingsystemrelease/$architecture",
      descr => "IUS Community repository",
      enabled => 1,
      gpgcheck => 0
   }
}

Then, for any node that extends base you can say

class foo {
   package { "bar": ensure => installed, require => Yumrepo["IUS"] }
}

This will ensure that

  • The package bar will not be installed unless the IUS repository is defined
  • The package will not attempt to install before the IUS repository is defined

Solution 2:

Although stages can handle this and so can specific yum repo dependencies, better is to declare the relationship generically.

Just put Yumrepo <| |> -> Package <| provider != 'rpm' |> in your puppet manifest.

node default {
  Yumrepo <| |> -> Package <| provider != 'rpm' |>
}

This makes it so that all yumrepo types will get processed before any packages that don't have 'rpm' as their provider. That latter exclusion is so that I can use the (for example) epel-release RPM package to help install the yum repo.

Solution 3:

(I found this question after I replied almost the same.. so thought my answer applies here as well and it's worth repeating it (it's safer to have an answer in two places..)

As far as I understand, this is exactly what stages are for -- they let you group and order class executions. I use "stages" to update and configure APT at Debian servers, which should be very similar to what you are going to do with YUM.

First of all, you declare "yum" stage at top level (above "nodes"), so that classes in "yum" stage will be executed before "main" ones:

stage { 'yum' : before => Stage['main'] }

Then, you assign stage to the classes. You can do this right in your node definition:

node default {
  class { 'yumrepos' : stage => yum }

  include packages
}