Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First commit

  • Loading branch information...
commit f848bac6072f99e1cd60a0cc0b84e5679c598dab 0 parents
Jeff Wallace authored
50 README.md
@@ -0,0 +1,50 @@
+# Apt module for Puppet
+
+## Description
+Provides helpful definitions for dealing with Apt.
+
+## Usage
+
+### apt::force
+Force a package to be installed from a specific release. Useful when using repositoires like Debian unstable in Ubuntu.
+<pre>
+apt::force { "glusterfs-server":
+ release => "unstable",
+ version => '3.0.3',
+ require => Apt::Source["debian_unstable"],
+}
+</pre>
+
+### apt::pin
+Add an apt pin for a certain release.
+<pre>
+apt::pin { "karmic": priority => 700 }
+apt::pin { "karmic-updates": priority => 700 }
+apt::pin { "karmic-security": priority => 700 }
+</pre>
+
+### apt::ppa
+Add a ppa repository using `add-apt-repository`. Somewhat experimental.
+<pre>
+apt::ppa { "ppa:drizzle-developers/ppa" }
+</pre>
+
+### apt::release
+Set the default apt release. Useful when using repositoires like Debian unstable in Ubuntu.
+<pre>
+apt::release { "karmic": }
+</pre>
+
+## apt::source
+Add an apt source to `/etc/apt/sources.list.d/`.
+<pre>
+apt::source { "debian_unstable":
+ location => "http://debian.mirror.iweb.ca/debian/",
+ release => "unstable",
+ repos => "main contrib non-free",
+ required_packages => "debian-keyring debian-archive-keyring",
+ key => "55BE302B",
+ key_server => "subkeys.pgp.net",
+ pin => "-10"
+}
+</pre>
21 manifests/debian/testing.pp
@@ -0,0 +1,21 @@
+# testing.pp
+
+class apt::debian::testing {
+
+ # deb http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
+ # deb-src http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
+ # Key: 55BE302B Server: subkeys.pgp.net
+ # debian-keyring
+ # debian-archive-keyring
+
+ apt::source { "debian_testing":
+ location => "http://debian.mirror.iweb.ca/debian/",
+ release => "testing",
+ repos => "main contrib non-free",
+ required_packages => "debian-keyring debian-archive-keyring",
+ key => "55BE302B",
+ key_server => "subkeys.pgp.net",
+ pin => "-10"
+ }
+
+}
21 manifests/debian/unstable.pp
@@ -0,0 +1,21 @@
+# unstable.pp
+
+class apt::debian::unstable {
+
+ # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
+ # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
+ # Key: 55BE302B Server: subkeys.pgp.net
+ # debian-keyring
+ # debian-archive-keyring
+
+ apt::source { "debian_unstable":
+ location => "http://debian.mirror.iweb.ca/debian/",
+ release => "unstable",
+ repos => "main contrib non-free",
+ required_packages => "debian-keyring debian-archive-keyring",
+ key => "55BE302B",
+ key_server => "subkeys.pgp.net",
+ pin => "-10"
+ }
+
+}
16 manifests/force.pp
@@ -0,0 +1,16 @@
+# force.pp
+# force a package from a specific release
+
+define apt::force(
+ $release = 'testing',
+ $version = false
+) {
+
+ exec { "aptitude -y -t ${release} install ${name}":
+ unless => $version ? {
+ false => "dpkg -l | grep ${name}",

As I could understand you do grepping through the package list on machine, which may lead to bad results, in case package with the same substring is installed, like -dev suffix or exim-daemon-light/exim-daemon-heavy.
I'd suggest to use dpkg -p for package checking like:
coolcold@nekotaz:~$ dpkg -p dpkg|grep Package ;echo $?
Package: dpkg
0
coolcold@nekotaz:~$ dpkg -p dpkgg|grep Package ;echo $?
Package `dpkgg' is not available.
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
1

What do you think about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ default => "dpkg -l | grep ${name} | grep ${version}"
+ }
+ }
+
+}
27 manifests/init.pp
@@ -0,0 +1,27 @@
+# apt.pp
+
+class apt {
+ $root = '/etc/apt'
+ $provider = 'apt-get'
+
+ file { "sources.list":
+ name => "${root}/sources.list",
+ ensure => present,
+ owner => root,
+ group => root,
+ mode => 644,
+ }
+
+ file { "sources.list.d":
+ name => "${root}/sources.list.d",
+ ensure => directory,
+ owner => root,
+ group => root,
+ }
+
+ exec { "apt_update":
+ command => "${provider} update",
+ subscribe => [ File["sources.list"], File["sources.list.d"] ],
+ refreshonly => true,
+ }
+}
20 manifests/pin.pp
@@ -0,0 +1,20 @@
+# pin.pp
+# pin a release in apt, useful for unstable repositories
+
+define apt::pin(
+ $packages = '*',
+ $priority = 0
+) {
+
+ include apt
+
+ file { "${name}.pref":
+ name => "${apt::root}/preferences.d/${name}",
+ ensure => file,
+ owner => root,
+ group => root,
+ mode => 644,
+ content => "# ${name}\nPackage: ${packages}\nPin: release a=${name}\nPin-Priority: ${priority}",
+ }
+
+}
13 manifests/ppa.pp
@@ -0,0 +1,13 @@
+# ppa.pp
+
+define apt::ppa(
+
+) {
+ include apt
+
+ exec { "add-apt-repository ${name}":
+ require => Package["python-software-properties"],
+ # TODO: unless => 'check'
+ }
+}
+
14 manifests/release.pp
@@ -0,0 +1,14 @@
+# release.pp
+
+define apt::release (
+
+) {
+ include apt
+
+ file { "${apt::root}/apt.conf.d/01release":
+ owner => root,
+ group => root,
+ mode => 644,
+ content => "APT::Default-Release \"${name}\";"
+ }
+}
50 manifests/source.pp
@@ -0,0 +1,50 @@
+# source.pp
+# add an apt source
+
+define apt::source(
+ $location = '',
+ $release = 'karmic',
+ $repos = 'main',
+ $include_src = true,
+ $required_packages = false,
+ $key = false,
+ $key_server = 'keyserver.ubuntu.com',
+ $pin = false
+) {
+
+ include apt
+
+ file { "${name}.list":
+ name => "${apt::root}/sources.list.d/${name}.list",
+ ensure => file,
+ owner => root,
+ group => root,
+ mode => 644,
+ content => template("apt/source.list.erb"),
+ }
+
+ if $pin != false {
+ apt::pin { "${release}": priority => "${pin}" }
+ }
+
+ exec { "${name} apt update":
+ command => "${apt::provider} update",
+ subscribe => File["${name}.list"],
+ refreshonly => true,
+ }
+
+ if $required_packages != false {
+ exec { "${apt::provider} -y install ${required_packages}":
+ subscribe => File["${name}.list"],
+ refreshonly => true,
+ }
+ }
+
+ if $key != false {
+ exec { "apt-key adv --keyserver ${key_server} --recv-keys ${key}":
+ unless => "apt-key list | grep ${key}",
+ before => File["${name}.list"],
+ }
+ }
+
+}
5 templates/source.list.erb
@@ -0,0 +1,5 @@
+# <%= name %>
+deb <%= location %> <%= release %> <%= repos %>
+<%- if include_src then -%>
+deb-src <%= location %> <%= release %> <%= repos %>
+<%- end -%>
Please sign in to comment.
Something went wrong with that request. Please try again.