只有课程可以设置'舞台';像XXX这样的普通资源无法改变运行阶段

时间:2014-10-03 21:30:48

标签: puppet

我有一个清单,其中包取决于apt::source资源。我试图通过设置一个阶段来确保apt::source先运行:

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'
}

但是,我遇到了以下错误:

==> 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

任何指针都将受到赞赏。

2 个答案:

答案 0 :(得分:1)

如果确实想要使用阶段,则应将适当的资源包装在(可能是专用的)类中。

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

并声明它像

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

请注意,不鼓励使用舞台。

如果您不使用虚拟资源,您可以通过此关系获得所需的效果:

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

答案 1 :(得分:0)

我最终决定采用这种方式:

include apt

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

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

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