Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a question about virtual resources in puppet. If I have:

class foo::virtual
{
  define foo () {
    custom_resource { $name:
      <attributes>,
      }
  }
  @foo { '1st_foo':
    <attributes>,
  }
}

I can realize(Foo::Virtual::Foo['1st_foo']) in a node declaration.

However, I would like to extract the specification of each virtual foo into a separate location, somewhere apart from the specification of class foo::virtual and define foo().

By way of analogy, I have a class called common::data that provides default values for various variables:

  class common::data {
    $barList = [ 'a','b','z']
  }

Is there some way I can declare @foo { '2nd_foo': } from within common::data? And then refer to that in a node declaration?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Yes, you can use that define outside the class it's created in, but you may need to include the class to ensure the define is parsed first, and the name of the individual resource is based on the class the define is in, not where the class is called.

Here's a complete working tested example (tested on CLI with puppet apply and correct nodename):

class foo::virtual {
  define foo() { notify { "test${title}": message => "realized foo ${title}" } }
  @foo { '1st_foo': }
}

class common::data {
  include foo::virtual
  @foo::virtual::foo { '2nd_foo': }
}

node default {
  include common::data
  realize(Foo::Virtual::Foo['1st_foo'])
  realize(Foo::Virtual::Foo['2nd_foo'])
}

Output confirms that both happen:

notice: realized foo 1st_foo
notice: realized foo 2nd_foo
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.