Make sure we configure the proxy before doing apt-get update.
--- /dev/null
+# This adds the necessary components to get backports for ubuntu and debian
+#
+# == Parameters
+#
+# [*release*]
+# The ubuntu/debian release name. Defaults to $lsbdistcodename. Setting this
+# manually can cause undefined behavior. (Read: universe exploding)
+#
+# == Examples
+#
+# include apt::backports
+#
+# class { 'apt::backports':
+# release => 'natty',
+# }
+#
+# == Authors
+#
+# Ben Hughes, I think. At least blame him if this goes wrong. I just added puppet doc.
+#
+# == Copyright
+#
+# Copyright 2011 Puppet Labs Inc, unless otherwise noted.
+class apt::backports(
+ $release = $lsbdistcodename,
+ $location = $apt::params::backports_location
+) inherits apt::params {
+
+ $release_real = downcase($release)
+
+ apt::source { 'backports.list':
+ location => $location,
+ release => "${release_real}-backports",
+ repos => $lsbdistid ? {
+ 'debian' => 'main contrib non-free',
+ 'ubuntu' => 'universe multiverse restricted',
+ },
+ key => $lsbdistid ? {
+ 'debian' => '55BE302B',
+ 'ubuntu' => '437D05B5',
+ },
+ key_server => 'pgp.mit.edu',
+ pin => '200',
+ notify => Exec["apt_update"],
+ }
+}
--- /dev/null
+define apt::conf (
+ $priority = '50',
+ $content
+ ) {
+
+ include apt::params
+
+ $apt_conf_d = $apt::params::apt_conf_d
+
+ file { "${apt_conf_d}/${priority}${name}":
+ ensure => file,
+ content => $content,
+ owner => root,
+ group => root,
+ mode => '0644',
+ }
+}
# testing.pp
class apt::debian::testing {
+ include apt
# 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_server => 'subkeys.pgp.net',
pin => '-10',
}
-
}
# unstable.pp
class apt::debian::unstable {
+ include apt
# 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_server => 'subkeys.pgp.net',
pin => '-10',
}
-
}
exec { "/usr/bin/aptitude -y -t ${release} install ${name}${version_string}":
unless => $install_check,
}
-
}
false => undef,
true => "# Repos managed by puppet.\n",
}
+
+ $root = $apt::params::root
+ $apt_conf_d = $apt::params::apt_conf_d
+ $sources_list_d = $apt::params::sources_list_d
+ $provider = $apt::params::provider
+
file { 'sources.list':
ensure => present,
- path => "${apt::params::root}/sources.list",
+ path => "${root}/sources.list",
owner => root,
group => root,
mode => '0644',
file { 'sources.list.d':
ensure => directory,
- path => "${apt::params::root}/sources.list.d",
+ path => $sources_list_d,
owner => root,
group => root,
purge => $purge_sources_list_d,
}
exec { 'apt_update':
- command => "${apt::params::provider} update",
+ command => "${provider} update",
subscribe => [ File['sources.list'], File['sources.list.d'] ],
refreshonly => $refresh_only_apt_update,
}
file { '99unauth':
ensure => present,
content => "APT::Get::AllowUnauthenticated 1;\n",
- path => '/etc/apt/apt.conf.d/99unauth',
+ path => "${apt_conf_d}/99unauth",
}
}
false: {
file { '99unauth':
ensure => absent,
- path => '/etc/apt/apt.conf.d/99unauth',
+ path => "${apt_conf_d}/99unauth",
}
}
undef: { } # do nothing
if ($proxy_host) {
file { 'configure-apt-proxy':
- path => '/etc/apt/apt.conf.d/proxy',
+ path => "${apt_conf_d}/proxy",
content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
notify => Exec['apt_update'],
}
$root = '/etc/apt'
$provider = '/usr/bin/apt-get'
$sources_list_d = "${root}/sources.list.d"
+ $apt_conf_d = "${root}/apt.conf.d"
+ $preferences_d = "${root}/preferences.d"
+
+ case $lsbdistid {
+ 'debian': {
+ $backports_location = 'http://backports.debian.org/debian-backports'
+ }
+ 'ubuntu': {
+ case $lsbdistcodename {
+ 'hardy','lucid','maverick','natty','oneiric','precise': {
+ $backports_location = 'http://us.archive.ubuntu.com/ubuntu'
+ }
+ default: {
+ $backports_location = 'http://old-releases.ubuntu.com/ubuntu'
+ }
+ }
+ }
+ }
}
include apt::params
+ $preferences_d = $apt::params::preferences_d
+
file { "${name}.pref":
ensure => file,
- path => "${apt::params::root}/preferences.d/${name}",
+ path => "${preferences_d}/${name}",
owner => root,
group => root,
mode => '0644',
include apt::params
+ $sources_list_d = $apt::params::sources_list_d
+
if ! $release {
fail('lsbdistcodename fact not available: release parameter required')
}
exec { "apt-update-${name}":
- command => '/usr/bin/aptitude update',
+ command => "${apt::params::provider} update",
refreshonly => true,
}
exec { "add-apt-repository-${name}":
command => "/usr/bin/add-apt-repository ${name}",
notify => Exec["apt-update-${name}"],
- creates => "${apt::params::sources_list_d}/${sources_list_d_filename}",
+ creates => "${sources_list_d}/${sources_list_d_filename}",
}
- file { "${apt::params::sources_list_d}/${sources_list_d_filename}":
+ file { "${sources_list_d}/${sources_list_d_filename}":
ensure => file,
require => Exec["add-apt-repository-${name}"];
}
-
}
include apt::params
- file { "${apt::params::root}/apt.conf.d/01release":
+ $root = $apt::params::root
+
+ file { "${root}/apt.conf.d/01release":
owner => root,
group => root,
mode => '0644',
include apt::params
+ $sources_list_d = $apt::params::sources_list_d
+ $provider = $apt::params::provider
+
if $release == undef {
fail('lsbdistcodename fact not available: release parameter required')
}
file { "${name}.list":
ensure => file,
- path => "${apt::params::root}/sources.list.d/${name}.list",
+ path => "${sources_list_d}/${name}.list",
owner => root,
group => root,
mode => '0644',
}
if $pin != false {
- apt::pin { $release: priority => $pin } -> File["${name}.list"]
+ apt::pin { $release:
+ priority => $pin,
+ before => File["${name}.list"]
+ }
}
exec { "${name} apt update":
- command => "${apt::params::provider} update",
+ command => "${provider} update",
subscribe => File["${name}.list"],
refreshonly => true,
}
if $required_packages != false {
exec { "Required packages: '${required_packages}' for ${name}":
- command => "${apt::params::provider} -y install ${required_packages}",
+ command => "${provider} -y install ${required_packages}",
subscribe => File["${name}.list"],
refreshonly => true,
}
--- /dev/null
+require 'spec_helper'
+describe 'apt::backports', :type => :class do
+
+ describe 'when turning on backports for ubuntu karmic' do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Karmic',
+ 'lsbdistid' => 'Ubuntu'
+ }
+ end
+
+ it { should contain_apt__source('backports.list').with({
+ 'location' => 'http://old-releases.ubuntu.com/ubuntu',
+ 'release' => 'karmic-backports',
+ 'repos' => 'universe multiverse restricted',
+ 'key' => '437D05B5',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ 'notify' => 'Exec[apt_update]'
+ })
+ }
+ end
+
+ describe "when turning on backports for debian squeeze" do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Squeeze',
+ 'lsbdistid' => 'Debian',
+ }
+ end
+
+ it { should contain_apt__source('backports.list').with({
+ 'location' => 'http://backports.debian.org/debian-backports',
+ 'release' => 'squeeze-backports',
+ 'repos' => 'main contrib non-free',
+ 'key' => '55BE302B',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ 'notify' => 'Exec[apt_update]'
+ })
+ }
+ end
+
+ describe "when turning on backports for debian squeeze but using your own mirror" do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Squeeze',
+ 'lsbdistid' => 'Debian'
+ }
+ end
+
+ let :location do
+ 'http://mirrors.example.com/debian-backports'
+ end
+
+ let :params do
+ { 'location' => location }
+ end
+
+ it { should contain_apt__source('backports.list').with({
+ 'location' => location,
+ 'release' => 'squeeze-backports',
+ 'repos' => 'main contrib non-free',
+ 'key' => '55BE302B',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ 'notify' => 'Exec[apt_update]'
+ })
+ }
+ end
+end
--- /dev/null
+require 'spec_helper'
+describe 'apt::conf', :type => :define do
+ let :title do
+ 'norecommends'
+ end
+
+ describe "when creating an apt preference" do
+ let :params do
+ {
+ :priority => '00',
+ :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ }
+ end
+
+ let :filename do
+ "/etc/apt/apt.conf.d/00norecommends"
+ end
+
+ it { should contain_apt__conf('norecommends').with({
+ 'priority' => '00',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ })
+ }
+
+ it { should contain_file(filename).with({
+ 'ensure' => 'file',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ end
+end