From 4d28e6668f0c26d7484198c1cdf418c83898b3c7 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 13:58:59 +0200 Subject: introduce preferences snippet Now, we have the possibility to externally add snippes, so that we can preferences for packages that are for example only in backports or unstable. --- README | 19 ++++++++----------- manifests/default_preferences.pp | 16 ---------------- manifests/init.pp | 24 ++++++------------------ manifests/module_dir.pp | 3 +++ manifests/preferences.pp | 28 ++++++++++++++++++++++++++++ manifests/preferences_snippet.pp | 11 +++++++++++ manifests/unattended_upgrades.pp | 2 +- 7 files changed, 57 insertions(+), 46 deletions(-) delete mode 100644 manifests/default_preferences.pp create mode 100644 manifests/module_dir.pp create mode 100644 manifests/preferences.pp create mode 100644 manifests/preferences_snippet.pp diff --git a/README b/README index e624bba..b52a024 100644 --- a/README +++ b/README @@ -50,17 +50,6 @@ following variable before including this class will pull in the templates/apt/sources.list file: $custom_sources_list ='template("apt/sources.list")' -$custom_preferences --------------------- -By default this module will use a basic apt/preferences file with -unstable and testing pinned to very low values so that any package -installation will not accidentally pull in packages from those suites -unless you explicitly specify the version number. You can set this -variable to pull in a customized apt/preferences template, for -example, setting the following variable before including this class -will pull in the templates/apt/preferences file: -$custom_preferences = 'template("apt/preferences")' - $custom_key_dir --------------- If you have different apt-key files that you want to get added to your @@ -81,6 +70,14 @@ Classes This module contains only the apt class, which sets up all described functionality. +Defines +======= + +apt::preferences_snippet +------------------------ + +A way to add pinning information to /etc/apt/preferences + Resources ========= diff --git a/manifests/default_preferences.pp b/manifests/default_preferences.pp deleted file mode 100644 index 3cdb355..0000000 --- a/manifests/default_preferences.pp +++ /dev/null @@ -1,16 +0,0 @@ -class apt::default_preferences { - config_file { - # this just pins unstable and testing to very low values - "/etc/apt/preferences": - content => template("apt/preferences.erb"), - # use File[apt_config] to reference a completed configuration - # See "The Puppet Semaphor" 2007-06-25 on the puppet-users ML - alias => apt_config, - # only update together - require => File["/etc/apt/sources.list"]; - # little default settings which keep the system sane - "/etc/apt/apt.conf.d/from_puppet": - content => "APT::Get::Show-Upgraded true;\nDSelect::Clean $real_apt_clean;\n", - before => Config_file[apt_config]; - } -} diff --git a/manifests/init.pp b/manifests/init.pp index 78ae6c5..12096a0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,18 +29,7 @@ class apt { } } - case $custom_preferences { - '': { - include apt::default_preferences - } - default: { - config_file { "/etc/apt/preferences": - content => $custom_preferences, - alias => apt_config, - require => File["/etc/apt/sources.list"]; - } - } - } + include apt::preferences if $apt_unattended_upgrades { include apt::unattended_upgrades @@ -58,13 +47,12 @@ class apt { command => '/usr/bin/apt-get update && sleep 1', refreshonly => true, subscribe => [ File["/etc/apt/sources.list"], - File["/etc/apt/preferences"], File["/etc/apt/apt.conf.d"], - Config_file[apt_config] ]; + Concatenated_file[apt_config] ]; 'update_apt': command => '/usr/bin/apt-get update && /usr/bin/apt-get autoclean', require => [ File["/etc/apt/sources.list"], - File["/etc/apt/preferences"], Config_file[apt_config] ], + File["/etc/apt/preferences"], Concatenated_file[apt_config] ], loglevel => info, # Another Semaphor for all packages to reference alias => apt_updated; @@ -88,7 +76,7 @@ class apt { alias => "backports_key", refreshonly => true, subscribe => File["${apt_base_dir}/backports.org.key"], - before => [ File[apt_config], Package["debian-backports-keyring"] ] + before => [ Concatenated_file[apt_config], Package["debian-backports-keyring"] ] } } lenny: { @@ -105,7 +93,7 @@ class apt { alias => "backports_key", refreshonly => true, subscribe => File["${apt_base_dir}/backports.org.key"], - before => [ Config_file[apt_config], Package["debian-backports-keyring"] ] + before => [ Concatenated_file[apt_config], Package["debian-backports-keyring"] ] } } } @@ -120,7 +108,7 @@ class apt { alias => "custom_keys", subscribe => File["${apt_base_dir}/keys.d"], refreshonly => true, - before => Config_file[apt_config]; + before => Concatenated_file[apt_config]; } } diff --git a/manifests/module_dir.pp b/manifests/module_dir.pp new file mode 100644 index 0000000..6dcfca3 --- /dev/null +++ b/manifests/module_dir.pp @@ -0,0 +1,3 @@ +class apt::module_dir { + module_dir{'apt': } +} diff --git a/manifests/preferences.pp b/manifests/preferences.pp new file mode 100644 index 0000000..b106153 --- /dev/null +++ b/manifests/preferences.pp @@ -0,0 +1,28 @@ +class apt::preferences { + + include apt::module_dir + module_dir{'apt/preferences': } + concatenated_file{'/etc/apt/preferences': + dir => '/var/lib/puppet/modules/apt/preferences', + header => 'Package: * +Pin: release a=unstable +Pin-Priority: 1 + +Package: * +Pin: release a=testing +Pin-Priority: 2 +', + # use Concatenated_file[apt_config] to reference a completed configuration + # See "The Puppet Semaphor" 2007-06-25 on the puppet-users ML + alias => apt_config, + # only update together + require => File["/etc/apt/sources.list"]; + } + + config_file { + # little default settings which keep the system sane + "/etc/apt/apt.conf.d/from_puppet": + content => "APT::Get::Show-Upgraded true;\nDSelect::Clean $real_apt_clean;\n", + before => Concatenated_file[apt_config]; + } +} diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp new file mode 100644 index 0000000..52edf97 --- /dev/null +++ b/manifests/preferences_snippet.pp @@ -0,0 +1,11 @@ +define apt::preferences_snippet( + $ensure => 'present', + $content +){ + file { "/var/lib/puppet/modules/apt/preferences/${name}": + ensure => $ensure, + content => "${content}\n", + notify => Exec['concat_/var/lib/puppet/modules/apt/preferences'], + owner => root, group => 0, mode => 0600; + } +} diff --git a/manifests/unattended_upgrades.pp b/manifests/unattended_upgrades.pp index c984c40..9a6c13b 100644 --- a/manifests/unattended_upgrades.pp +++ b/manifests/unattended_upgrades.pp @@ -9,7 +9,7 @@ class apt::unattended_upgrades { content => 'APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Unattended-Upgrade "1"; ', - before => Config_file[apt_config], + before => Concatenated_file[apt_config], require => Package['unattended-upgrades'], } } -- cgit v1.2.3 From 822d482f4d6e94546cb5454d571b4d58525af94b Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 14:13:02 +0200 Subject: improve prefrences snippet --- manifests/preferences_snippet.pp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp index 52edf97..8d82a42 100644 --- a/manifests/preferences_snippet.pp +++ b/manifests/preferences_snippet.pp @@ -1,10 +1,14 @@ define apt::preferences_snippet( - $ensure => 'present', - $content + $ensure = 'present', + $release, + $priority ){ file { "/var/lib/puppet/modules/apt/preferences/${name}": ensure => $ensure, - content => "${content}\n", + content => "Package: ${name} +Pin: release a=${release} +Pin-Priority: ${priority} +", notify => Exec['concat_/var/lib/puppet/modules/apt/preferences'], owner => root, group => 0, mode => 0600; } -- cgit v1.2.3 From b989192dfd5c6604afe6e0562f9d39a7487b6cf4 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 14:27:27 +0200 Subject: fix modules directory stuff --- manifests/module_dir.pp | 3 --- manifests/preferences.pp | 5 +++-- manifests/preferences_snippet.pp | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) delete mode 100644 manifests/module_dir.pp diff --git a/manifests/module_dir.pp b/manifests/module_dir.pp deleted file mode 100644 index 6dcfca3..0000000 --- a/manifests/module_dir.pp +++ /dev/null @@ -1,3 +0,0 @@ -class apt::module_dir { - module_dir{'apt': } -} diff --git a/manifests/preferences.pp b/manifests/preferences.pp index b106153..e806f9f 100644 --- a/manifests/preferences.pp +++ b/manifests/preferences.pp @@ -1,9 +1,10 @@ class apt::preferences { - include apt::module_dir + include common::moduledir + $apt_preferences_dir = "${common::moduledir::module_dir_path}/apt/preferences" module_dir{'apt/preferences': } concatenated_file{'/etc/apt/preferences': - dir => '/var/lib/puppet/modules/apt/preferences', + dir => $apt_preferences_dir, header => 'Package: * Pin: release a=unstable Pin-Priority: 1 diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp index 8d82a42..e5393bd 100644 --- a/manifests/preferences_snippet.pp +++ b/manifests/preferences_snippet.pp @@ -3,13 +3,14 @@ define apt::preferences_snippet( $release, $priority ){ - file { "/var/lib/puppet/modules/apt/preferences/${name}": + include apt::preferences_snippet + file { "${apt::preferences::apt_preferences_dir}/${name}": ensure => $ensure, content => "Package: ${name} Pin: release a=${release} Pin-Priority: ${priority} ", - notify => Exec['concat_/var/lib/puppet/modules/apt/preferences'], + notify => Exec["concat_${apt::preferences::apt_preferences_dir}"], owner => root, group => 0, mode => 0600; } } -- cgit v1.2.3 From 80ad2d086edb86456c3e944f7f440fbaf96cfad3 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 14:29:01 +0200 Subject: fix classname --- manifests/preferences_snippet.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp index e5393bd..71c095b 100644 --- a/manifests/preferences_snippet.pp +++ b/manifests/preferences_snippet.pp @@ -3,7 +3,7 @@ define apt::preferences_snippet( $release, $priority ){ - include apt::preferences_snippet + include apt::preferences file { "${apt::preferences::apt_preferences_dir}/${name}": ensure => $ensure, content => "Package: ${name} -- cgit v1.2.3 From 68842b2f968a6da6a9b654f5da8d061f429d991b Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 14:36:28 +0200 Subject: fix header file --- manifests/preferences.pp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/manifests/preferences.pp b/manifests/preferences.pp index e806f9f..479e910 100644 --- a/manifests/preferences.pp +++ b/manifests/preferences.pp @@ -3,9 +3,8 @@ class apt::preferences { include common::moduledir $apt_preferences_dir = "${common::moduledir::module_dir_path}/apt/preferences" module_dir{'apt/preferences': } - concatenated_file{'/etc/apt/preferences': - dir => $apt_preferences_dir, - header => 'Package: * + file{"${apt_preferences_dir}_header": + content => 'Package: * Pin: release a=unstable Pin-Priority: 1 @@ -13,6 +12,11 @@ Package: * Pin: release a=testing Pin-Priority: 2 ', + } + + concatenated_file{'/etc/apt/preferences': + dir => $apt_preferences_dir, + header => "${apt_preferences_dir}_header", # use Concatenated_file[apt_config] to reference a completed configuration # See "The Puppet Semaphor" 2007-06-25 on the puppet-users ML alias => apt_config, -- cgit v1.2.3 From b497ed88efd04852cb4deefacc9b19b9a3f625d6 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 14:40:27 +0200 Subject: empty line between snippets --- manifests/preferences.pp | 1 + manifests/preferences_snippet.pp | 1 + 2 files changed, 2 insertions(+) diff --git a/manifests/preferences.pp b/manifests/preferences.pp index 479e910..232b8f7 100644 --- a/manifests/preferences.pp +++ b/manifests/preferences.pp @@ -11,6 +11,7 @@ Pin-Priority: 1 Package: * Pin: release a=testing Pin-Priority: 2 + ', } diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp index 71c095b..21dfe86 100644 --- a/manifests/preferences_snippet.pp +++ b/manifests/preferences_snippet.pp @@ -9,6 +9,7 @@ define apt::preferences_snippet( content => "Package: ${name} Pin: release a=${release} Pin-Priority: ${priority} + ", notify => Exec["concat_${apt::preferences::apt_preferences_dir}"], owner => root, group => 0, mode => 0600; -- cgit v1.2.3 From 9d1a018eedee3f65e2651cd1e3bdd9da5ae5518d Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 14:43:06 +0200 Subject: improve example --- README | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README b/README index b52a024..5f8225a 100644 --- a/README +++ b/README @@ -78,6 +78,13 @@ apt::preferences_snippet A way to add pinning information to /etc/apt/preferences +Example: + + apt::preferences_snippet{ + 'irssi-plugin-otr': + release => 'lenny-backports', + priority => 999; + } Resources ========= -- cgit v1.2.3 From e19c94dcd20c966143c933e22d5a63f350649b6e Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 17 Oct 2010 15:18:08 +0200 Subject: minor improvements, especially do not refresh apt every run --- README | 4 ++-- manifests/init.pp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README b/README index 5f8225a..833008e 100644 --- a/README +++ b/README @@ -89,8 +89,8 @@ Example: Resources ========= -File[apt_config] ----------------- +Concatenated_file[apt_config] +----------------------------- Use this resource to depend on or add to a completed apt configuration Exec[apt_updated] diff --git a/manifests/init.pp b/manifests/init.pp index 12096a0..675c78d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -46,13 +46,13 @@ class apt { 'refresh_apt': command => '/usr/bin/apt-get update && sleep 1', refreshonly => true, - subscribe => [ File["/etc/apt/sources.list"], - File["/etc/apt/apt.conf.d"], - Concatenated_file[apt_config] ]; + subscribe => File['/etc/apt/sources.list', + '/etc/apt/apt.conf.d', + '/etc/apt/preferences']; 'update_apt': command => '/usr/bin/apt-get update && /usr/bin/apt-get autoclean', - require => [ File["/etc/apt/sources.list"], - File["/etc/apt/preferences"], Concatenated_file[apt_config] ], + require => File['/etc/apt/sources.list', + '/etc/apt/preferences'], loglevel => info, # Another Semaphor for all packages to reference alias => apt_updated; -- cgit v1.2.3 From ebcda455df36aefac48bb831192f2b4e7af8fafc Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Sun, 17 Oct 2010 20:36:45 -0400 Subject: Make $apt_clean effective in all cases The file "/etc/apt/apt.conf.d/from_puppet" is currently only defined when $custom_sources_list is not used (it is declared in default_preferences). Bring this file up in the apt class so that using custom sources doesn't remove its addition. Signed-off-by: Gabriel Filion --- manifests/default_preferences.pp | 4 ---- manifests/init.pp | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/manifests/default_preferences.pp b/manifests/default_preferences.pp index 3cdb355..4752fad 100644 --- a/manifests/default_preferences.pp +++ b/manifests/default_preferences.pp @@ -8,9 +8,5 @@ class apt::default_preferences { alias => apt_config, # only update together require => File["/etc/apt/sources.list"]; - # little default settings which keep the system sane - "/etc/apt/apt.conf.d/from_puppet": - content => "APT::Get::Show-Upgraded true;\nDSelect::Clean $real_apt_clean;\n", - before => Config_file[apt_config]; } } diff --git a/manifests/init.pp b/manifests/init.pp index 98ec91c..9ef1cea 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,6 +29,13 @@ class apt { } } + config_file { + # little default settings which keep the system sane + "/etc/apt/apt.conf.d/from_puppet": + content => "APT::Get::Show-Upgraded true;\nDSelect::Clean $real_apt_clean;\n", + before => Config_file[apt_config]; + } + case $custom_preferences { '': { include apt::default_preferences -- cgit v1.2.3 From 8175bff077112fc7b1397f082f1fbac56474feb8 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Sun, 17 Oct 2010 20:42:09 -0400 Subject: Add a proxy-client class The module currently doesn't have a handy way of making a server get its packages via a proxy. Add a "proxy-client" class that makes this easy. $apt_proxy declares the proxy server's fqdn $apt_proxy_port declares the port used for connection Signed-off-by: Gabriel Filion --- manifests/proxy-client.pp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 manifests/proxy-client.pp diff --git a/manifests/proxy-client.pp b/manifests/proxy-client.pp new file mode 100644 index 0000000..ea0a29c --- /dev/null +++ b/manifests/proxy-client.pp @@ -0,0 +1,18 @@ +class apt::proxy-client { + + $real_apt_proxy = $apt_proxy ? { + "" => "localhost", + default => $apt_proxy + } + + $real_apt_proxy_port = $apt_proxy_port ? { + "" => "3142", + default => $apt_proxy_port + } + + file { "/etc/apt/apt.conf.d/20proxy": + ensure => present, + content => "Acquire::http { Proxy \"http://$real_apt_proxy:$real_apt_proxy_port\"; };\n", + owner => root, group => 0, mode => 0644; + } +} -- cgit v1.2.3 From 973657848100d227c10f4b51a23bf24a56550c8d Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Mon, 18 Oct 2010 01:43:24 -0400 Subject: Remove unnecessary exec When $custom_key_dir has not been assigned any value, a useless exec of /bin/true is run. Remove this by using 'if' instead of 'case'. Signed-off-by: Gabriel Filion --- manifests/init.pp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 9ef1cea..57a685c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -78,26 +78,21 @@ class apt { package { "debian-archive-keyring": ensure => latest } # backports uses the normal archive key now package { "debian-backports-keyring": ensure => absent } - - case $custom_key_dir { - '': { - exec { "/bin/true # no_custom_keydir": } + + if $custom_key_dir { + file { "${apt_base_dir}/keys.d": + source => "$custom_key_dir", + recurse => true, + mode => 0755, owner => root, group => root, } - default: { - file { "${apt_base_dir}/keys.d": - source => "$custom_key_dir", - recurse => true, - mode => 0755, owner => root, group => root, - } - exec { "find ${apt_base_dir}/keys.d -type f -exec apt-key add '{}' \\; && apt-get update": - alias => "custom_keys", - subscribe => File["${apt_base_dir}/keys.d"], - refreshonly => true, - before => Config_file["apt_config"]; - } + exec { "find ${apt_base_dir}/keys.d -type f -exec apt-key add '{}' \\; && apt-get update": + alias => "custom_keys", + subscribe => File["${apt_base_dir}/keys.d"], + refreshonly => true, + before => Config_file["apt_config"]; } } # workaround for preseeded_package component file { [ "/var/cache", "/var/cache/local", "/var/cache/local/preseeding" ]: ensure => directory } -} +} -- cgit v1.2.3 From 4dbcd092817708292de6463777b331c8dbc7e727 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Mon, 18 Oct 2010 01:45:22 -0400 Subject: Make it possible to ensure preferences is absent The current code makes it mandatory to have a file /etc/apt/preferences present. In the event that this file is empty or contains a space, apt-get update cannot execute. Add a case with the special value "false" that ensures the file does not exist. Signed-off-by: Gabriel Filion --- README | 4 ++++ manifests/init.pp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/README b/README index 131ae1d..dbcf383 100644 --- a/README +++ b/README @@ -62,6 +62,10 @@ example, setting the following variable before including this class will pull in the templates/apt/preferences file: $custom_preferences = 'template("apt/preferences")' +Also, if you need the preferences file to be absent, set this variable to false: + +$custom_preferences = false + $custom_key_dir --------------- If you have different apt-key files that you want to get added to your diff --git a/manifests/init.pp b/manifests/init.pp index 57a685c..60c95a1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -40,6 +40,12 @@ class apt { '': { include apt::default_preferences } + false: { + config_file { "/etc/apt/preferences": + alias => "apt_config", + ensure => absent; + } + } default: { config_file { "/etc/apt/preferences": content => $custom_preferences, -- cgit v1.2.3 From 5bf01f148d2c2db8523febc0d73591444c5965c9 Mon Sep 17 00:00:00 2001 From: nadir Date: Fri, 22 Oct 2010 19:18:12 +0200 Subject: notify => Exec['refresh_apt'] --- manifests/custom_sources.pp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/manifests/custom_sources.pp b/manifests/custom_sources.pp index cd7b8fc..c9e0b9c 100644 --- a/manifests/custom_sources.pp +++ b/manifests/custom_sources.pp @@ -1,10 +1,7 @@ define apt::custom_sources_template ($sources_file = "") { file { "/etc/apt/sources.list.d/$sources_file": content => template($name), + notify => Exec['refresh_apt'] } - exec { "/usr/bin/apt-get update": - subscribe => File["/etc/apt/sources.list.d/$sources_file"], - refreshonly => true, - } - } +} -- cgit v1.2.3