1

I'm using Puppet (version 2.7.19) with Vagrant to setup a dev box for a project. I have the Puppet classes for all the dependencies I need, however for my Vagrant box I need to run an apt-get update first. I've wrapped that logic in a class called "vagrant::bootstrap".

Because I want to keep my other classes as "box neutral" as possible, I wrote the following node definition in my site.pp so that my Vagrant box specific needs don't pollute the config for other machines.

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
}

}

All the modules get loaded correctly as far as I can tell, however I see Puppet trying to install apache2 before the apt-get update run finishes

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

Looking through the Puppet docs, the examples I've seen of require are with classes not nodes eg: http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html#declaring-a-class-with-require

Am I expecting the wrong thing of Puppet here? I want to state that vagrant::bootstrap needs to be the first thing run before anything else; then all the other packages will install correctly.

2

Right, require won't work for this, the dependency-building behavior applies to the class that it's called from (which doesn't work when it's from a node). One approach would be to use resource chaining:

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

Or, alternatively, simply make the bootstrap a requirement for your package installation:

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"],
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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