For this part of my comparison series “Cfengine 3 vs. Puppet” I upgraded my Linux Mint 12 to 13 and switched to Puppet 3.0.2. If you download and try my little code snippets I recommend to use at least Puppet 2.7.14 since this version is able to run the official apt module from Puppetlabs. While [...]
For this part of my comparison series “Cfengine 3 vs. Puppet” I upgraded my Linux Mint 12 to 13 and switched to Puppet 3.0.2. If you download and try my little code snippets I recommend to use at least Puppet 2.7.14 since this version is able to run the official apt module from Puppetlabs.
While the fifth part in my Cfengine 3 blog series was about managing apt sources lists with Cfengine 3, this blog post will cover the same topic except that we use Puppet instead of the other configuration management tool from Oslo, Norway.
Writing the Puppet manifest for managing apt sources.list files
include apt
apt::source { "puppetlabs_precise":
location => "http://apt.puppetlabs.com/",
release => "precise",
repos => " main",
include_src => false
}
apt::source { "ubuntu_archiv_precise":
location => "http://archive.ubuntu.com/",
release => "precise",
repos => "main restricted universe multiverse",
include_src => false
}
apt::source { "ubuntu_archiv_precise-updates":
location => "http://archive.ubuntu.com/",
release => "precise-updates",
repos => "main restricted universe multiverse",
include_src => false
}
apt::source { "ubuntu_archiv_precise-security":
location => "http://archive.ubuntu.com/",
release => "precise-security",
repos => "main restricted universe multiverse",
include_src => false
}
apt::source { "canonical_archiv_precise":
location => "http://archive.canonical.com/ubuntu/",
release => "precise",
repos => "partner",
include_src => false
}
apt::source { "linuxmint_maya":
location => "http://packages.linuxmint.com/",
release => "maya",
repos => "main upstream import",
include_src => false
}
The sample above will only work with the official apt module from Puppetlabs, so make sure you install it before you run the Puppet manifest:
puppet module install puppetlabs/apt Notice: Preparing to install into /etc/puppet/modules ... Notice: Downloading from https://forge.puppetlabs.com ... Notice: Installing -- do not interrupt ... /etc/puppet/modules └─┬ puppetlabs-apt (v1.1.0) └── puppetlabs-stdlib (v3.2.0) puppet apply /etc/puppet/manifests/xenuser_org-005-managing_apt_sources_lists.pp
What now happens is that Puppet creates a bunch of files in /etc/apt/sources.list.d/ and runs apt-get update.
Lets verify that our Puppet manifest works:
cd /etc/apt/sources.list.d ls -la total 40 drwxr-xr-x 2 root root 4096 Feb 3 20:48 . drwxr-xr-x 7 root root 4096 Feb 3 20:48 .. -rw-r--r-- 1 root root 84 Feb 3 20:42 canonical_archiv_precise.list -rw-r--r-- 1 root root 78 Feb 3 20:42 linuxmint_maya.list -rw-r--r-- 1 root root 50 Jun 20 2012 local-repository.list -rw-r--r-- 1 root root 49 Jun 20 2012 local-repository.list.save -rw-r--r-- 1 root root 66 Feb 3 20:42 puppetlabs_precise.list -rw-r--r-- 1 root root 99 Feb 3 20:42 ubuntu_archiv_precise.list -rw-r--r-- 1 root root 117 Feb 3 20:42 ubuntu_archiv_precise-security.list -rw-r--r-- 1 root root 115 Feb 3 20:42 ubuntu_archiv_precise-updates.list
Go ahead and have a look at those files
Analyzing the code snippet and summary
Instead of editing the file /etc/apt/sources.list directly (like I did in the Cfengine 3 version of this code snippet), we let Puppet create single sources.list files for every “apt source”. The downside of this approach is that we have to define a “release” for each “section” of the same release name (e.g. precise, precise-updates…).
While this is definitely a good and clean approach for managing apt sources.list files, we now have more complexity in comparison to the single file approach. However, I think that using the apt Puppet module is the right way to do it.
As usual, you can download today’s Puppet manifest here.
Update from February 10th, 2013:
As Jean Rémond suggested in the comment below, you could also use “${::lsbdistcodename} instead of directly naming the distri version name, such as precise. However, in my example, using this variable brought “lisa” as the result (although my Linux Mint was updated from version 12 “Lisa” to version 13 “Maya”).
Here is the code snippet I used:
apt::source { "test":
location => "http://test.test.com/",
release => "${::lsbdistcodename}",
repos => "main upstream import",
include_src => false
}
There might be a better way than writing “precise” or “maya” directly into the Puppet manifest; maybe I’ll cover that in another blog post.

Comments on this entry (3 comments)
Did you like this post? You can share your opinion with us! Simply click here.