Ask Your Question

Require one out of many?

asked 2014-04-16 08:44:33 -0500

Heiko gravatar image

updated 2014-04-16 08:44:50 -0500

Hi folks,

on RHEL 6.4 I have to install a package, let's say "A", which is located in two yum repos. Since this module may be installed in environments where one or two yum repositories out of two are present, I have to set up a requirement "one out of many".

So, is there a way to do something like follows?

class module_a::install{
  package { 'a':
      ensure => latest,
      require => Yumrepo[ 'repo1', 'repo2' ],

But: It requires repo1 OR repo2 to be present. If both are present, no problem. If none, set it up in another class.

edit retag flag offensive close merge delete


Are both repo1 and repo2 managed by puppet?

spuder gravatar imagespuder ( 2014-04-16 11:08:38 -0500 )edit

Yes, both repos are managed by puppet. Must be, since they are a required resource, mustn't? Generally, the situation may sound odd, but there are hosts having one of ...(more)

Heiko gravatar imageHeiko ( 2014-04-16 23:57:58 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-19 19:41:57 -0500

solarkennedy gravatar image

I could think of a couple ways to solve this.

The first is to require the "Class" that sets up your repos, instead of the repos directly. For example:

class my_repos {
  if $dev {
    require repo1
  } elsif $staging {
    require repo1
    require repo2
  } elsif $prod {
    require repo2

Then you can say:

package { 'a':
  ensure => latest,
  require => Class['my_repos'],

Or, if you know in advance that this package comes from this repo, and that it will be declared (maybe), you could do:

yumrepo { 'repo1':
  before => Package['a']
yumrepo { 'repo2':
  before => Package['a']

And if they are defined, then they will be installed before the package is installed.

Sometimes you don't know what packages will be installed though, in these cases you might want to just make sure all repos are installed before any packages are installed:

Yumrepo <| |> -> Package

You could also do tags, run stages, if defined() tricks (not recommended), etc. But it will depend a bit on the specifics and scope of this particular problem. (is it just one package, lots of packages, lots of repos, etc)

edit flag offensive delete link more


The last hint (Yumrepo <| |> -> Package) seems to be the key to my problem's solution. I just have to be sure all necessary yum repos are defined prior to installing the package.

Heiko gravatar imageHeiko ( 2014-04-22 01:28:23 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2014-04-16 08:44:33 -0500

Seen: 122 times

Last updated: Apr 19 '14