Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In puppet it's possible to realize virtual resources with the realize function or with collections.

I'd like to know if it's possible to realize resources only with the realize function. As a simplified example, I'd want that with the followig manifest nginx is not installed, unless including nginx_conf module, that contains an implicit realize.

@package { 'nginx':
  ensure => present,

class nginx_conf {
  realize Package['nginx']

  file { '/etc/nginx/conf.d/foo':
    ensure => present,
    require => Package['nginx'],

exec { 'apt-get update': path => '/usr/bin' }

Exec['apt-get update'] -> Package <| |>

Any idea?

An option is to put the package inside a separate class that is required by the module that is going to realize it, but I'd like to know if there is some way to select virtual resources in collections only if they are realized, and don't realize them only by being included in collections.

share|improve this question
up vote 2 down vote accepted

There doesn't seem to be a complete way to prevent Package <| |> from realizing resources. This could be a partial solution:

@package { 'nginx':
  ensure  => present,
  tag     => optional,
  require => Exec['apt-get update'],

Exec['apt-get update'] -> Package <| tag != optional |>

You would have to define requirements for each virtual Package, then.

The underlying problem can be solved, though, by using Run Stages:

class update-apt {
  exec { 'apt-get update': path => '/usr/bin' }

stage { 'first': before => Stage['main'] }
class {'update-apt':
  stage => 'first',

All classes and resources are run in the main-Stage by default, so Exec['apt-get update'] is always run before any Package-resources.

share|improve this answer

Your Answer


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.