Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puppet apt-get update only once before anything else?

I know the basics of ordering in puppet to run apt-get update before a specific package but would like to specify to just run apt-get update only once and then execute the rest of the puppet file. Is that possible?

All of the ways listed Here need to either run apt-get before every package or use arrows or requires to specify each package.

like image 639
isimmons Avatar asked Jul 17 '13 00:07

isimmons


2 Answers

This would be my recommendation from that list:

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

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

This will ensure that the exec is run before any package, not that the exec is run before each package. In fact, any resource in puppet will only ever be executed at most once per puppet run.

But if you're wanting the exec to occur before ANY type of resource I guess you could do something like:

exec { "apt-update":
    command => "/usr/bin/apt-get update",
    before  => Stage["main"],
}

The "main" Stage is the default stage for each resource, so this would make the exec occur before anything else.

I hope that this helps.

like image 66
Sekm Avatar answered Sep 24 '22 13:09

Sekm


With puppetlabs-apt module, it should be enough to define dependency on the module for any package that will be installed:

Class['apt::update'] -> Package <| provider == 'apt' |>

This assumes basic configuration of apt, e.g.:

class { 'apt':
    update => {
      frequency => 'daily',
    },
    purge => {
      'sources.list' => false,
      'sources.list.d' => true,
    },
  }
like image 24
Tombart Avatar answered Sep 21 '22 13:09

Tombart