Using Puppet to Configure Ubuntu to use Apt-Cacher-NG

In this post, I’ll share a brief snippet of Puppet code that allows you to automatically configure Ubuntu clients to use Apt-Cacher-NG. By leveraging Apt-Cacher-NG, running apt-get commands on your Ubuntu instances will generally be faster because the Apt-Cacher-NG server will cache information locally instead of requiring that every command go out to the source repositories. In my own lab I’ve seen a tremendous speed boost on installing updates and frequently-used packages on my Ubuntu instances. You can get more information on Apt-Cacher-NG on the Apt-Cacher-NG website.

(Note: The Puppet code in this post relies upon the same Puppet Labs apt module that I used in my post on using Puppet to configure Ubuntu to use the Ubuntu Cloud Archive.)

This snippet of Puppet code will take care of configuring apt to use a local Apt-Cacher-NG instance:

(In the event the code block above isn’t shown, you can also see it here.)

This is a really simple block of code, but I’m publishing it here just for the sake of completeness and in the remote event someone else will find it useful. Because this a distro-specific thing (only applies to Debian and Debian derivatives like Ubuntu), you might want to wrap this in a conditional (like If $::osfamily == ‘Debian' or similar) to prevent errors in the event this manifest is (accidentally) applied to a non-Debian distribution.

Questions, corrections, and other feedback are welcome, so feel free to speak up in the comments below.

Tags: , , ,

  1. Dee Abson’s avatar

    Very interesting! The Apt-Catcher-NG got me thinking about those of us with Synology NAS devices in our home labs, and low and behold: http://code.opoki.com/apt-cacher-ng-synology-diskstation/