apt-mirror Module for Puppet

Here is my solution to maintaining Development, Staging, and Production apt mirrors on a “deployment” server with Puppet. I assume the reader is familiar with Puppet and has a working Puppet infrastructure.

Let’s start with the site.pp file and work our way down to the actual module. I’ll include the whole site.pp file since it’ll give you an idea of the directory layout. Generally, each Puppet node has an individual configuration file under node/ with their IP configuration, and includes the OS distribution type and role(s).

The deployment server, which hosts the Development, Staging, and Production apt mirrors, has a node configuration that includes the following (ip and dhcp server information has been removed).

The included ubuntu::vmware class configures this node as an Ubuntu server running under vmware (installs the open-vm-tools, for example), and the DOMAINNAME::deploy class configures this node as a “deployment” server offering apt mirrors (among other infrastructure services).

Here’s an example of the role/DOMAINNAME-deploy.pp file. I’ve left out the dhcp server, squid proxy, apt and yum repository configurations, etc., leaving just the relevant apt mirror sections. The apt::mirror class (from the module) creates the /etc/apt/mirror.list.d/ directory, while the apt::mirror::* definitions create the apt-mirror configuration files within.

The apt::mirror definitions reside in the apps/apt-mirror.pp file, and each definition within that file calls apt::mirror::repository from the apt mirror module itself. The uri, dist, and components arguments are essential, and you may also include source (true/false) to add a dev-src to the mirror, ensure (present/absent) to add/remove the apt-mirror configuration file, and sched (daily|hourly|monthly|weekly) to update the mirror on a schedule (default is no schedule).

The apt mirror module resides in modules/apt/manifests/mirror.pp and provides the apt::mirror definition, which creates the /etc/apt/mirror.list.d/ directory, and the apt::mirror::repository definition, which creates the individual apt-mirror configuration files within.

The apt::mirror::repository definition uses the templates/apt/mirror.list.erb template.

I chose to keep the template outside the module directory since the base_path and other parameters may differ for each installation.