From e5f2dfe294a563f5ebcec3d31949a81e1815db6e Mon Sep 17 00:00:00 2001 From: Cody Herriges Date: Wed, 11 Apr 2012 14:54:13 -0700 Subject: [PATCH] Adds apt::{conf,backports} and variable style. With the addition of this patch two new defines will be added; one to manage APT configuration files (apt::conf) and one that abstracts out the requirements needed to turn on backport repositories (apt::backports). In addition, the patch takes the opportunity to clean up variable definitions so they follow a consistent pattern of setting local variables to the fully qualified value stored in the apt::params class. Previously all variable used within a class directly addressed the apt::params namespace when ever the variable was used. In the pattern they now adhere to we can more easily switch the namespace data lives in or externalize it even more using hiera. --- manifests/backports.pp | 45 ++++++++++++++++++++++++++++++++++++ manifests/conf.pp | 17 ++++++++++++++ manifests/debian/testing.pp | 2 +- manifests/debian/unstable.pp | 2 +- manifests/force.pp | 1 - manifests/init.pp | 18 ++++++++++----- manifests/params.pp | 18 +++++++++++++++ manifests/pin.pp | 4 +++- manifests/ppa.pp | 7 +++--- manifests/release.pp | 4 +++- manifests/source.pp | 9 +++++--- 11 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 manifests/backports.pp create mode 100644 manifests/conf.pp diff --git a/manifests/backports.pp b/manifests/backports.pp new file mode 100644 index 0000000..6734e05 --- /dev/null +++ b/manifests/backports.pp @@ -0,0 +1,45 @@ +# 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_locations +) inherits apt::params { + + apt::source { 'backports.list': + location => $location, + release => "${release}-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-get update"], + } +} + diff --git a/manifests/conf.pp b/manifests/conf.pp new file mode 100644 index 0000000..6be1a67 --- /dev/null +++ b/manifests/conf.pp @@ -0,0 +1,17 @@ +define apt::conf ( + $priority = '50', + $content + ) { + + include apt::params + + $root = "${apt::params::root}" + $apt_conf_d = "${apt::params::apt_conf_d}" + + file { "${apt_conf_d}/${priority}${name}": + content => $content, + owner => root, + group => root, + mode => 0644, + } +} diff --git a/manifests/debian/testing.pp b/manifests/debian/testing.pp index cfdeb3c..4513347 100644 --- a/manifests/debian/testing.pp +++ b/manifests/debian/testing.pp @@ -1,6 +1,7 @@ # 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 @@ -17,5 +18,4 @@ class apt::debian::testing { key_server => 'subkeys.pgp.net', pin => '-10', } - } diff --git a/manifests/debian/unstable.pp b/manifests/debian/unstable.pp index 3991023..401c9c5 100644 --- a/manifests/debian/unstable.pp +++ b/manifests/debian/unstable.pp @@ -1,6 +1,7 @@ # 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 @@ -17,5 +18,4 @@ class apt::debian::unstable { key_server => 'subkeys.pgp.net', pin => '-10', } - } diff --git a/manifests/force.pp b/manifests/force.pp index 45c5679..0089bbd 100644 --- a/manifests/force.pp +++ b/manifests/force.pp @@ -18,5 +18,4 @@ define apt::force( exec { "/usr/bin/aptitude -y -t ${release} install ${name}${version_string}": unless => $install_check, } - } diff --git a/manifests/init.pp b/manifests/init.pp index 29db697..5668d11 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -45,9 +45,15 @@ class apt( 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', @@ -56,7 +62,7 @@ class apt( 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, @@ -64,7 +70,7 @@ class apt( } exec { 'apt_update': - command => "${apt::params::provider} update", + command => "${provider} update", subscribe => [ File['sources.list'], File['sources.list.d'] ], refreshonly => $refresh_only_apt_update, } @@ -74,13 +80,13 @@ class apt( 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 @@ -89,7 +95,7 @@ class apt( 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}\";", } } diff --git a/manifests/params.pp b/manifests/params.pp index ca5d655..79989c0 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -2,4 +2,22 @@ class apt::params { $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/ubuntuk + } + default: { + $backports_location = 'http://old-releases.ubuntu.com/ubuntu', + } + } + } + } } diff --git a/manifests/pin.pp b/manifests/pin.pp index 4661366..2899fce 100644 --- a/manifests/pin.pp +++ b/manifests/pin.pp @@ -8,9 +8,11 @@ define apt::pin( 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', diff --git a/manifests/ppa.pp b/manifests/ppa.pp index 095d8f1..2e4daa5 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -8,6 +8,8 @@ define apt::ppa( include apt::params + $sources_list_d = $apt::params::sources_list_d + if ! $release { fail('lsbdistcodename fact not available: release parameter required') } @@ -24,13 +26,12 @@ define apt::ppa( 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}"]; } - } diff --git a/manifests/release.pp b/manifests/release.pp index ee94e13..6e0a38f 100644 --- a/manifests/release.pp +++ b/manifests/release.pp @@ -6,7 +6,9 @@ class apt::release ( 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', diff --git a/manifests/source.pp b/manifests/source.pp index 95768dc..3d4011e 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -16,13 +16,16 @@ define apt::source( 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 => "${apt::params::sources_list_d}/${name}.list", owner => root, group => root, mode => '0644', @@ -34,14 +37,14 @@ define apt::source( } 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, } -- 2.45.2