Search code examples
puppet

Only classes can set 'stage'; normal resources like XXX cannot change run stage


I have a manifest where a package depends on an apt::source resource. I've tried to make sure the apt::source runs first by setting a stage:

include apt

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

apt::source { 'erlang_repo':
  location => 'http://packages.erlang-solutions.com/ubuntu',
  repos    => 'contrib',
  key      => 'A14F4FCA',
  stage    => first
}

package { 'erlang':
  ensure   => '1:17.3'
}

However, I'm hitting the following error:

==> default: Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Only classes can set 'stage'; normal resources like Apt::Source[erlang_repo] cannot change run stage at /tmp/manifests/default.pp:12 on node vagrant-ubuntu-trusty-64.home
==> default: Wrapped exception:
==> default: Only classes can set 'stage'; normal resources like Apt::Source[erlang_repo] cannot change run stage
==> default: Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Only classes can set 'stage'; normal resources like Apt::Source[erlang_repo] cannot change run stage at /tmp/manifests/default.pp:12 on node vagrant-ubuntu-trusty-64.home

Any pointers will be appreciated.


Solution

  • If you really want to use stages, you should wrap the appropriate resources in (possibly dedicated) classes.

    class site::apt_sources {
        apt::source { ... }
    }
    

    and declare it like

    class { 'site::apt_sources': stage => first }
    

    Please note that the use of stages is discouraged.

    If you don't use virtual resources, you can probably achieve the desired effect through this relationship instead:

    Apt::Source<| |> -> Package<| |>