1
votes

I'm working with Puppet Agents living inside of Docker containers, so using as little filesystem space as possible is of high importance. Therefore, at the very end of my Docker bulid, I was running the following:

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

The problem is that my Puppet runs try to install a package, and since there are no lists to pull from, it fails. A simple apt-get update allows everything to run properly.

I'm running the latest Puppet 3 client available from their repository. How can I use stages to require the following wrapping each Puppet run:

  1. Before anything, run apt-get update, only if the Puppet catalog for this instance has changed. (ie: if nothing has changed, don't do anything, don't update, as it's a waste of cycles, bandwidth, resources, etc.)
  2. After everything, run apt-get clean to clean everything out and possibly run the equivalent of the Docker RUN command listed above.

How can I use Puppet execution stages to intelligently wrap the Puppet run, updating apt beforehand and wiping the cache afterward?

1
I don't think that Puppet comes with a good way to inquire whether the received catalog is different from the previous one. Perhaps you can build some scriptwork around Puppet like 1. fetch catalog and do a noop 2. when changes are detected, do apt update 3. actual puppet run 4. cleanup. - Felix Frank

1 Answers

0
votes

If you use puppetlabs-apt module, just define:

Class['apt'] -> Package<| |>

Otherwise use:

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

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

This way apt update will be executed in case that some package is missing.