]> gitweb.fluxo.info Git - puppet-apt.git/commitdiff
refactor: simplify and remove inline content
authorGabriel Filion <lelutin@gmail.com>
Mon, 25 Oct 2010 04:14:33 +0000 (00:14 -0400)
committerGabriel Filion <lelutin@gmail.com>
Mon, 25 Oct 2010 04:14:33 +0000 (00:14 -0400)
Simplifications: make apt_conf_snippet repeat less code, make code that
generates sources.list more concise.

Remove all inline content in favor of templates and static files.
The ability to include sources for static files was needed for
the main 'preferences' file, so it was added to the preferences_snippet
define.

Signed-off-by: Gabriel Filion <lelutin@gmail.com>
files/preferences [moved from templates/preferences.erb with 99% similarity]
files/preferences_snippet.erb [new file with mode: 0644]
manifests/apt_conf_snippet.pp
manifests/init.pp
manifests/preferences.pp
manifests/preferences_snippet.pp

similarity index 99%
rename from templates/preferences.erb
rename to files/preferences
index ac71582439a8d5c0d41f92afc229d65ddc947e8a..e893b7e15a8cc826af238ee9e6413a7d5e41ffde 100644 (file)
@@ -5,3 +5,4 @@ Pin-Priority: 1
 Package: *
 Pin: release a=testing
 Pin-Priority: 2
+
diff --git a/files/preferences_snippet.erb b/files/preferences_snippet.erb
new file mode 100644 (file)
index 0000000..4dfb701
--- /dev/null
@@ -0,0 +1,4 @@
+Package: <%= name %>
+Pin: release a=<%= release %>
+Pin-Priority: <%= priority %>
+
index 77b88aef53de46e609ec4851f2e936f0630a5e6f..c1cd884111ec1348447ee0a92c87861d9dc7c3e9 100644 (file)
@@ -10,20 +10,20 @@ define apt::apt_conf_snippet(
     fail("Only one of \$source or \$content must specified for apt_conf_snippet ${name}")
   }
 
+  file { "/etc/apt/apt.conf.d/${name}":
+    ensure => $ensure,
+    notify => Exec["refresh_apt"],
+    owner => root, group => 0, mode => 0600;
+  }
+
   if $source {
-    file { "/etc/apt/apt.conf.d/${name}":
-      ensure => $ensure,
+    File["/etc/apt/apt.conf.d/${name}"] {
       source => $source,
-      notify => Exec["refresh_apt"],
-      owner => root, group => 0, mode => 0600;
     }
   }
   else {
-    file { "/etc/apt/apt.conf.d/${name}":
-      ensure => $ensure,
+    File["/etc/apt/apt.conf.d/${name}"] {
       content => $content,
-      notify => Exec["refresh_apt"],
-      owner => root, group => 0, mode => 0600;
     }
   }
 }
index 0e4bd5ccac4e181b04893e1bbbb14ba427f403f9..7d683037d8392cae99df29981812779fdff28924 100644 (file)
@@ -19,23 +19,16 @@ class apt {
   }
 
   include lsb
-  case $custom_sources_list {
-    '': {
-      config_file {
-        # include main, security and backports
-        # additional sources should be included via the custom_sources_template
-        # define
-        "/etc/apt/sources.list":
-          content => template( "apt/$operatingsystem/sources.list.erb"),
-          require => Package['lsb'];
-      }
-    }
-    default: {
-      config_file { "/etc/apt/sources.list":
-        content => $custom_sources_list,
-        require => Package['lsb'];
-      }
-    }
+  config_file {
+    # include main, security and backports
+    # additional sources should be included via the custom_sources_template
+    # define
+    "/etc/apt/sources.list":
+      content => $custom_sources_list ? {
+        '' => template( "apt/$operatingsystem/sources.list.erb"),
+        default => $custom_sources_list
+      },
+      require => Package['lsb'];
   }
 
   # 01autoremove already present by default
@@ -109,4 +102,4 @@ class apt {
 
   # workaround for preseeded_package component
   file { [ "/var/cache", "/var/cache/local", "/var/cache/local/preseeding" ]: ensure => directory }
-}     
+}
index 772b426500320c360e142bccb98989f1982facc5..5be3bd08bcad90d5269d75afa4f98a02a295244a 100644 (file)
@@ -4,18 +4,9 @@ class apt::preferences {
   $apt_preferences_dir = "${common::moduledir::module_dir_path}/apt/preferences"
   module_dir{'apt/preferences': }
   file{"${apt_preferences_dir}_header":
-    content => $custom_preferences ? {
-      '' => 'Package: *
-Pin: release a=unstable
-Pin-Priority: 1
-
-Package: *
-Pin: release a=testing
-Pin-Priority: 2
-
-',
-      default => $custom_preferences
-    },
+    source => ["puppet:///modules/site-apt/${fqdn}/preferences",
+               "puppet:///modules/site-apt/preferences",
+               "puppet:///modules/apt/preferences"]
   }
 
   concatenated_file{'/etc/apt/preferences':
index 21dfe86e5ab0ec3e5b62a3f5edce4f86890ba292..a723206a1ad84e066362f8d52ebf223bce106269 100644 (file)
@@ -1,17 +1,29 @@
 define apt::preferences_snippet(
   $ensure = 'present',
+  $source = '',
   $release,
   $priority
 ){
   include apt::preferences
+
   file { "${apt::preferences::apt_preferences_dir}/${name}":
     ensure => $ensure,
-    content => "Package: ${name}
-Pin: release a=${release}
-Pin-Priority: ${priority}
-
-",
+    #TODO this template is somewhat limited
     notify => Exec["concat_${apt::preferences::apt_preferences_dir}"],
     owner => root, group => 0, mode => 0600;
   }
+
+  # This should really work in the same manner as sources_list and apt_conf
+  # snippets, but since the preferences.d directory cannot be used in Debian
+  # lenny, we can't generalize without going into ugly special-casing.
+  case $source {
+    '' =>
+      File["${apt::preferences::apt_preferences_dir/${name}"] {
+        content => template("apt/preferences_snippet.erb")
+      },
+    default =>
+      File["${apt::preferences::apt_preferences_dir/${name}"] {
+        source => $source
+      }
+  }
 }