0
votes

I'm very new to Puppet, and can't seem to find the answer to this question. I have a defined Puppet resource that takes a few arguments:

class xy::xy {
  include apache:regular_apache
  define setup($pkg_name, $xy_version, $pas_ver) {
    file { '/etc/xy':
           ensure => present,
           notify => Service['apache'],
  }
}

I'm trying to require this custom resource for another resource in another file.

class soft::buy {
  include xy::xy

  $xt_requires = [Xy::Xy::Setup["{'xt_buy': pkg_name => 'xt_buy_v01', 
                                            xy_version => '1.0.1',
                                            pas_version => '2.1.4'}"]]

  package { 'buy.xt':
    ensure => $::buy_xt_version,
    provider => 'xt',
    require => $xt_requires,
  }
}

The error that I get is this: Syntax error at 'require'; expected '}'

From reading the Puppet docs, it seems like I'm missing a comma or colon somewhere, but I've tried a variety of things. I was wondering how to properly require a custom defined resource with parameters for another resource? Thanks!

1

1 Answers

4
votes

The syntax error can be fixed by the following code snippet.

package { 'buy.xt':
  ensure => $::buy_xt_version,
  provider => 'xt',
  require => $xt_requires
}

[EDIT: The original code defines $xt_requires, not $requires]

You are defining the parameter require (which defines which resource needs to be handled first).

This is different from the language statement require (which is including a class and adding a dependency on the required class).

However, in the require-paramter, you cannot specify the parameters for the requirement, just it's presence. Fully correct would be:

xy::xy::setup {'xt_buy':
  pkg_name => 'xt_buy_v01', 
  xy_version => '1.0.1',
  pas_version => '2.1.4'
}

package { 'buy.xt':
  ensure => $::buy_xt_version,
  provider => 'xt',
  require => Xy::Xy::Setup['xt_buy']
}