Trigger apt-get update if packages are to be installed

491 views
Skip to first unread message

Simon Weald

unread,
Jun 6, 2016, 11:14:50 AM6/6/16
to Puppet Users
Hi everyone

I've got a little bit of an issue which I'm currently fighting with. At the moment, we pass an array of packages to be installed to the package resource, however I need to call an apt-get update prior to the package installation (in case we add a new repo etc). My snippet below should probably give you a good idea of what I want to achieve:

$installpackages = hiera_array('installed-packages')
 
exec { "apt-update":
 command => "/usr/bin/apt-get update",
 refreshonly => true,
}
 
package { $installpackages:
 ensure => 'present',
 require => Exec['apt-update'],
}

Obviously my goal is to have the update only run if any packages are actually going to be installed - I can't use empty() against the array as it will always contain content.

Can anyone suggest how I can achieve this?

Thanks!

Matt Zagrabelny

unread,
Jun 6, 2016, 11:33:02 AM6/6/16
to puppet...@googlegroups.com
We're using the puppetlabs apt resource and a line like:

Apt::Source <| |> -> Package <| |>

to ensure that any Apt::Source is processed before any package installation.

I know this doesn't quite do the updating - we do that daily via cron,
but it does demonstrate the global dependency ordering of sources and
packages.

Hope that helps!

-m

Christopher Wood

unread,
Jun 6, 2016, 11:42:46 AM6/6/16
to puppet...@googlegroups.com
Back when I was doing this on Debian/Ubuntu I ended up doing the apt-get update on every agent run. This didn't stress the apt proxy (far from it) and made sure the agent had an up to date view of apt every time no matter what.

This would also cover if somebody uses ensure=>latest or ensure=>1.2.3.4 somewhere in the catalog.
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [1]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [2]https://groups.google.com/d/msgid/puppet-users/8c248cca-5174-4406-a145-0634bfcfce9e%40googlegroups.com.
> For more options, visit [3]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. mailto:puppet-users...@googlegroups.com
> 2. https://groups.google.com/d/msgid/puppet-users/8c248cca-5174-4406-a145-0634bfcfce9e%40googlegroups.com?utm_medium=email&utm_source=footer
> 3. https://groups.google.com/d/optout

Simon Weald

unread,
Jun 6, 2016, 5:16:04 PM6/6/16
to Puppet Users, christop...@pobox.com
This is what we used to do, but I'm trying to get away from that for two reasons. Firstly, to my mind it kinda goes against how Puppet is supposed to work, and secondly we use Puppetboard for monitoring and an apt-get update is recorded as a change meaning that every run results in a change even if nothing else has been applied. I'm not concerned about stressing our mirrors as they're meaty boxes, but removing the need to do it every time will also speed up the runs.

Simon Weald

unread,
Jun 6, 2016, 5:18:11 PM6/6/16
to Puppet Users
We currently use Debian's unattended-upgrades which will cause an apt-get update to be run at the same time (around 0500ish), however in this instance I made some changes to a manifest to pull in a new sources.list and then install packages from it - this the kind of scenario I'm attempting to find a way around.

Klavs Klavsen

unread,
Jul 7, 2017, 10:23:17 AM7/7/17
to Puppet Users
Did you ever find a good solution to this? found stuff like this: https://blog.bluemalkin.net/puppet-trick-running-apt-get-update-only-when-needed/ - but thats really ugly

Christopher Wood

unread,
Jul 7, 2017, 11:32:37 AM7/7/17
to puppet...@googlegroups.com
Not sure what their solution was, but mine was (back when puppeting Debian/Ubuntu) to run apt-get update on every run, but make sure to also run apt-cacher-ng to be an apt proxy on the local network. That sped things up.
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [1]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [2]https://groups.google.com/d/msgid/puppet-users/52bf65e9-5458-4053-95e5-842eaebe7203%40googlegroups.com.
> For more options, visit [3]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. mailto:puppet-users...@googlegroups.com
> 2. https://groups.google.com/d/msgid/puppet-users/52bf65e9-5458-4053-95e5-842eaebe7203%40googlegroups.com?utm_medium=email&utm_source=footer
> 3. https://groups.google.com/d/optout

Reply all
Reply to author
Forward
0 new messages