DEV Community

loading...

Hack: Forcing Puppet to apt update

Lars Quentin
CompSci and Math Double Major working as a software developer and IT support Just here to post snippets
・1 min read

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 🥧

Discussion (0)