DEV Community

Lars Quentin
Lars Quentin

Posted on

Hack: Forcing Puppet to apt update

Short hack: As seen in m a n y Dockerfiles, the apt cache is located at /var/lib/apt/lists.

Therefore, we can use it's existence to create an idempotent exec-Ressouce!

exec { 'apt update':
  # Only if the update files dont exist
  unless => '[ "$(ls -A /var/lib/apt/lists)" ]',
  # /bin is needed for bash
  # /usr/bin is needed for [
  path => '/bin:/usr/bin',
}
Enter fullscreen mode Exit fullscreen mode

Now whenever you need to have the apt cache first, just do something like

package { 'your-package':
  ensure => 'present',
  require => Exec['apt update']
}
Enter fullscreen mode Exit fullscreen mode

Easy as 🥧

Top comments (0)