From 4d0ddd005795592f56496d8d39dc37ee86fac038 Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Mon, 9 Apr 2012 01:33:13 -0400 Subject: Refactor: manage .d directories when using sources_list and apt_conf The .d directories are only managed by the main 'apt' class. However, both 'sources_list' and 'apt_conf' defines depend on those directories. So in practice, the defines have an implicit need for those directories to be somehow managed. Let's turn this into an explicit relation, and include the directories in the defines. This makes it possible to use both defines without having to include the main 'apt' class. (maybe when using puppet apply?) Signed-off-by: Gabriel Filion --- manifests/apt_conf.pp | 2 ++ manifests/dot_d_directories.pp | 22 ++++++++++++++++++++++ manifests/init.pp | 16 +--------------- manifests/sources_list.pp | 2 ++ 4 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 manifests/dot_d_directories.pp (limited to 'manifests') diff --git a/manifests/apt_conf.pp b/manifests/apt_conf.pp index c484ec3..03ae1ac 100644 --- a/manifests/apt_conf.pp +++ b/manifests/apt_conf.pp @@ -12,6 +12,8 @@ define apt::apt_conf( fail("Only one of \$source or \$content must specified for apt_conf ${name}") } + include apt::dot_d_directories + file { "/etc/apt/apt.conf.d/${name}": ensure => $ensure, notify => Exec["refresh_apt"], diff --git a/manifests/dot_d_directories.pp b/manifests/dot_d_directories.pp new file mode 100644 index 0000000..742aad4 --- /dev/null +++ b/manifests/dot_d_directories.pp @@ -0,0 +1,22 @@ +class apt::dot_d_directories { + + # watch .d directories and ensure they are present + file { + "/etc/apt/apt.conf.d": + ensure => directory, + checksum => mtime, + notify => Exec['refresh_apt']; + "/etc/apt/sources.list.d": + ensure => directory, + checksum => mtime, + notify => Exec['refresh_apt']; + } + + exec { + # "&& sleep 1" is workaround for older(?) clients + 'refresh_apt': + command => '/usr/bin/apt-get update && sleep 1', + refreshonly => true, + } + +} diff --git a/manifests/init.pp b/manifests/init.pp index b5be91f..0d58c61 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -128,21 +128,7 @@ class apt { require => [ Apt_conf['02show_upgraded'], Apt_conf['03clean'] ]; } - # watch .d directories and ensure they are present - file { "/etc/apt/apt.conf.d": ensure => directory, checksum => mtime; } - file { "/etc/apt/sources.list.d": - ensure => directory, - checksum => mtime, - notify => Exec['refresh_apt'], - } - - exec { - # "&& sleep 1" is workaround for older(?) clients - 'refresh_apt': - command => '/usr/bin/apt-get update && sleep 1', - refreshonly => true, - subscribe => [ File['/etc/apt/apt.conf.d'], Config_file['/etc/apt/sources.list'] ]; - } + include apt::dot_d_directories ## This package should really always be current package { "debian-archive-keyring": ensure => latest } diff --git a/manifests/sources_list.pp b/manifests/sources_list.pp index 86b35a7..edf7f22 100644 --- a/manifests/sources_list.pp +++ b/manifests/sources_list.pp @@ -11,6 +11,8 @@ define apt::sources_list ( fail("Only one of \$source or \$content must specified for apt_sources_snippet ${name}") } + include apt::dot_d_directories + file { "/etc/apt/sources.list.d/${name}": ensure => $ensure, owner => root, group => 0, mode => 0644; -- cgit v1.2.3 From a835369958226bac2d010fedb50ed5ef98b5906f Mon Sep 17 00:00:00 2001 From: Gabriel Filion Date: Mon, 9 Apr 2012 01:39:29 -0400 Subject: Force an apt-get update when changing an apt::sources_list sources_list doesn't currently force puppet to run 'apt-get update' after creating/modifying/removing files in sources.list.d. Signed-off-by: Gabriel Filion --- manifests/apt_conf.pp | 5 ++++- manifests/init.pp | 3 ++- manifests/sources_list.pp | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'manifests') diff --git a/manifests/apt_conf.pp b/manifests/apt_conf.pp index 03ae1ac..fe07546 100644 --- a/manifests/apt_conf.pp +++ b/manifests/apt_conf.pp @@ -14,10 +14,13 @@ define apt::apt_conf( include apt::dot_d_directories + # One would expect the 'file' resource on sources.list.d to trigger an + # apt-get update when files are added or modified in the directory, but it + # apparently doesn't. file { "/etc/apt/apt.conf.d/${name}": ensure => $ensure, + owner => root, group => 0, mode => 0644, notify => Exec["refresh_apt"], - owner => root, group => 0, mode => 0644; } if $source { diff --git a/manifests/init.pp b/manifests/init.pp index 0d58c61..4d65e77 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -85,7 +85,8 @@ class apt { '' => template( "apt/$operatingsystem/sources.list.erb"), default => $custom_sources_list }, - require => Package['lsb']; + require => Package['lsb'], + notify => Exec['refresh_apt'], } apt_conf { "02show_upgraded": diff --git a/manifests/sources_list.pp b/manifests/sources_list.pp index edf7f22..499116d 100644 --- a/manifests/sources_list.pp +++ b/manifests/sources_list.pp @@ -13,9 +13,13 @@ define apt::sources_list ( include apt::dot_d_directories + # One would expect the 'file' resource on sources.list.d to trigger an + # apt-get update when files are added or modified in the directory, but it + # apparently doesn't. file { "/etc/apt/sources.list.d/${name}": ensure => $ensure, - owner => root, group => 0, mode => 0644; + owner => root, group => 0, mode => 0644, + notify => Exec['refresh_apt'], } if $source { -- cgit v1.2.3 From 8996d83489159ec34187a18d18bc0d7566f2cbe5 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 5 Aug 2011 10:57:13 +0200 Subject: migrate concatenated_file to the concat module --- README | 1 + manifests/preferences.pp | 16 ++++++---------- manifests/preferences_snippet.pp | 10 ++++------ 3 files changed, 11 insertions(+), 16 deletions(-) (limited to 'manifests') diff --git a/README b/README index 31c715a..ba287d9 100644 --- a/README +++ b/README @@ -19,6 +19,7 @@ This module needs: - lsb-release installed - the common module: git://labs.riseup.net/shared-common +- the concat module: https://github.com/ripienaar/puppet-concat By default, on normal hosts, this module sets the configuration option DSelect::Clean to 'auto'. On virtual servers, the value is set by default to diff --git a/manifests/preferences.pp b/manifests/preferences.pp index 71ef0a6..f188149 100644 --- a/manifests/preferences.pp +++ b/manifests/preferences.pp @@ -1,9 +1,6 @@ class apt::preferences { - include common::moduledir - $apt_preferences_dir = "${common::moduledir::module_dir_path}/apt/preferences" - module_dir{'apt/preferences': } - file { "${apt_preferences_dir}_header": + concat::fragment{"apt_preferences_header": content => $custom_preferences ? { '' => $operatingsystem ? { 'debian' => template("apt/${operatingsystem}/preferences_${codename}.erb"), @@ -11,16 +8,15 @@ class apt::preferences { }, default => $custom_preferences }, + order => 00, + target => '/etc/apt/preferences', } - 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 + concat{'/etc/apt/preferences': alias => apt_config, # only update together - require => File["/etc/apt/sources.list"]; + require => File["/etc/apt/sources.list"], + owner => root, group => 0, mode => 0644; } } diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp index 4b8e575..bcc12de 100644 --- a/manifests/preferences_snippet.pp +++ b/manifests/preferences_snippet.pp @@ -11,11 +11,9 @@ define apt::preferences_snippet( include apt::preferences - file { "${apt::preferences::apt_preferences_dir}/${name}": + concat::fragment{"apt_preference_${name}": ensure => $ensure, - #TODO this template is somewhat limited - notify => Exec["concat_${apt::preferences::apt_preferences_dir}"], - owner => root, group => 0, mode => 0600; + target => '/etc/apt/preferences', } # This should really work in the same manner as sources_list and apt_conf @@ -23,12 +21,12 @@ define apt::preferences_snippet( # lenny, we can't generalize without going into ugly special-casing. case $source { '': { - File["${apt::preferences::apt_preferences_dir}/${name}"] { + Concat::Fragment[$name]{ content => template("apt/preferences_snippet.erb") } } default: { - File["${apt::preferences::apt_preferences_dir}/${name}"] { + Concat::Fragment[$name]{ source => $source } } -- cgit v1.2.3 From 5173c717154e1fba74bdc9a7227401bc7b398397 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 5 Aug 2011 11:12:29 +0200 Subject: use the correct name --- manifests/preferences_snippet.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'manifests') diff --git a/manifests/preferences_snippet.pp b/manifests/preferences_snippet.pp index bcc12de..91b3dde 100644 --- a/manifests/preferences_snippet.pp +++ b/manifests/preferences_snippet.pp @@ -21,12 +21,12 @@ define apt::preferences_snippet( # lenny, we can't generalize without going into ugly special-casing. case $source { '': { - Concat::Fragment[$name]{ + Concat::Fragment["apt_preference_${name}"]{ content => template("apt/preferences_snippet.erb") } } default: { - Concat::Fragment[$name]{ + Concat::Fragment["apt_preference_${name}"]{ source => $source } } -- cgit v1.2.3 From 56efade862ca11245fd504d5fb406ae12ee7c924 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 5 Aug 2011 11:22:05 +0200 Subject: use correct references for new concat usage --- README | 2 +- manifests/init.pp | 2 +- manifests/unattended_upgrades.pp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'manifests') diff --git a/README b/README index ba287d9..1b01f88 100644 --- a/README +++ b/README @@ -370,7 +370,7 @@ upgrade_package { "perl": Resources ========= -Concatenated_file[apt_config] +Concat[apt_config] ----------------------------- Use this resource to depend on or add to a completed apt configuration diff --git a/manifests/init.pp b/manifests/init.pp index 4d65e77..960f18d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -154,7 +154,7 @@ class apt { } if $custom_preferences != false { Exec["custom_keys"] { - before => Concatenated_file[apt_config], + before => Concat[apt_config], } } } diff --git a/manifests/unattended_upgrades.pp b/manifests/unattended_upgrades.pp index b90fcbb..f31a3fb 100644 --- a/manifests/unattended_upgrades.pp +++ b/manifests/unattended_upgrades.pp @@ -15,7 +15,7 @@ class apt::unattended_upgrades { if $custom_preferences != false { Apt_conf["50unattended-upgrades"] { - before => Concatenated_file[apt_config], + before => Concat[apt_config], } } } -- cgit v1.2.3