木偶需要function不做我想要的节点定义

我正在使用Vagrant的Puppet(版本2.7.19)为项目设置开发框。 我有我需要的所有依赖关系的Puppet类,但是对于我的Vagrant框,我需要首先运行apt-get更新。 我把这个逻辑包装在一个名为“vagrant :: bootstrap”的类中。

因为我想让我的其他类尽可能地保持“中性”,所以我在site.pp中写了下面的节点定义,这样我的Vagrant特定的需求就不会污染其他机器的configuration。

node default { require vagrant::bootstrap include base, puppet::agent, php::php54, apache2 } class apache2 { include apache2::install, apache2::service } class apache2::install { package { [ "apache2", "apache2-doc", "apache2-mpm-worker", "apache2-utils", "libapache2-mod-fcgid" ]: ensure => present } 

}

所有的模块被正确加载据我可以告诉,但是我看到木偶试图apt-get更新运行完成之前安装apache2

 err: /Stage[main]/Apache2::Install/Package[apache2-utils]/ensure: change from purged to present failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install apache2-utils' returned 100: Reading package lists... Building dependency tree... Reading state information... E: Unable to locate package apache2-utils 

通过Puppet文档查看,我看到的需求的例子是类不是节点例如: http : //docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html#declaring-a-class-with-require

我在这里期待Puppet的错误吗? 我想说明vagrant :: bootstrap需要在别的之前运行, 那么所有其他的软件包将正确安装。

正确的, require不会为此工作,依赖构build行为适用于从其调用的类(当它来自节点时不起作用)。 一种方法是使用资源链:

 node default { include vagrant::bootstrap, base, puppet::agent, php::php54, apache2 Class["vagrant::bootstrap"] -> Class["apache2"] } 

或者,也可以简单地使用bootstrap来安装软件包:

 class apache2 { # ..like this.. require vagrant::bootstrap include apache2::install, apache2::service } class apache2::install { package { [ "apache2", "apache2-doc", "apache2-mpm-worker", "apache2-utils", "libapache2-mod-fcgid" ]: ensure => present, # ..or like this. require => Class["vagrant::bootstrap"], } }