conditionally running apt-get update

72 views
Skip to first unread message

Vince Skahan

unread,
Dec 15, 2014, 4:27:24 PM12/15/14
to puppet...@googlegroups.com
In trying to spin up on puppet in a Vagrant environment, one of the things I have to do to my VM is 'apt-get update' at least once to catch the base box's understanding of what packages are where up to current.  That takes a long enough time that I'd like to do it just once, or very rarely rather than every time I run 'vagrant provision'

Right now, my toplevel manifest does the update once before trying to install anything.

exec { "run apt-get update":
  path    => '/usr/bin',
  command => 'apt-get update',
}

# install and configure nginx
class {'nginx': }


Ansible has a nice feature where you can specify how long you want the cache valid for, and it skips doing everything if the cache isn't that old (yet)

      - name: update apt cache
       apt: update_cache=yes cache_valid_time=84600


Is there something similar for Puppet, or can somebody suggest a reasonable workaround ?


Craig White

unread,
Dec 15, 2014, 5:04:48 PM12/15/14
to puppet...@googlegroups.com
I tend to create a directory with a minimal class /etc/puppet/deployfiles and then another class for custom apt stuff and I have a file in modules/apt/files where cron does a date thingy (/bin/date > /etc/puppet/modules/apt/files/apt_update_time) and then I have this module watch for a change which notifies an Exec in my apt module to trigger an apt-get update. It's convoluted but it works. Similarly I have an apt_upgrade_time file too but I don't have a cron job updating that one - I just run the date command manually to get machines to perform the apt-get upgrade but I do have machines run apt-get update daily triggered by the updated file from cron.
Reply all
Reply to author
Forward
0 new messages