]> gitweb.fluxo.info Git - puppet-apt.git/commitdiff
Repair Exec['update_apt'] to run apt-get update when needed.
authorintrigeri <intrigeri@boum.org>
Wed, 15 Dec 2010 08:47:57 +0000 (09:47 +0100)
committerintrigeri <intrigeri@boum.org>
Wed, 15 Dec 2010 08:47:57 +0000 (09:47 +0100)
Move this Exec to a dedicated class that is not included by default i.e. we
default not to "apt-get update" on every Puppet run.

We now make use of this class in the apt::upgrade_package define to make sure
APT indexes are up-to-date before attempting package upgrades.

One may now use the following to ensure current packages are installed by
Package resources:

  include apt::update
  Package { require => Exec[apt_updated] }

README
manifests/init.pp
manifests/update.pp [new file with mode: 0644]
manifests/upgrade_package.pp

diff --git a/README b/README
index 88eef47d46d7bcff6ec0f75c7ab50f850bdd74de..ddcd249a329fd8250d76d31e8fd9e80bd9b060c7 100644 (file)
--- a/README
+++ b/README
@@ -337,15 +337,16 @@ Use this resource to depend on or add to a completed apt configuration
 Exec[apt_updated]
 -----------------
 
-After this point, current packages can be installed via apt. It is usually used
-like this:
+After this point the APT indexes are up-to-date.
 
-Package { require => Exec[apt_updated] }
+This resource is usually used like this to ensure current packages are
+installed by Package resources:
 
-TODO
-====
+  include apt::update
+  Package { require => Exec[apt_updated] }
 
-Sometimes -- especially when initially starting management or deploying new
-packages -- a immediate update is really needed to be able to install the right
-packages without errors. Thus a method should be devised to be able to specify
-with high fidelity when a update should be run and when it is not needed.
+Please note that the apt::upgrade_package define automatically uses
+this resource so you don't have to manage this yourself if you need to
+make sure APT indexes are up-to-date before a package upgrade is
+attempted, but don't want "apt-get update" to happen on every Puppet
+run.
index 8a4a0a5fcf3adf7330f52e8873d65e8e1b61a70b..b5be91fc6ed5989fcfdc896aaa7d127f461ceb1f 100644 (file)
@@ -142,15 +142,6 @@ class apt {
       command => '/usr/bin/apt-get update && sleep 1',
       refreshonly => true,
       subscribe => [ File['/etc/apt/apt.conf.d'], Config_file['/etc/apt/sources.list'] ];
-
-    'update_apt':
-      command => '/usr/bin/apt-get update && /usr/bin/apt-get autoclean',
-      refreshonly => true,
-      require => [ File['/etc/apt/apt.conf.d', '/etc/apt/preferences' ],
-                   Config_file['/etc/apt/sources.list'] ],
-      loglevel => info,
-      # Another Semaphor for all packages to reference
-      alias => "apt_updated";
   }
 
   ## This package should really always be current
diff --git a/manifests/update.pp b/manifests/update.pp
new file mode 100644 (file)
index 0000000..ae992f4
--- /dev/null
@@ -0,0 +1,12 @@
+class apt::update {
+
+  exec { 'update_apt':
+    command => '/usr/bin/apt-get update && /usr/bin/apt-get autoclean',
+    require => [ File['/etc/apt/apt.conf.d', '/etc/apt/preferences' ],
+                 Config_file['/etc/apt/sources.list'] ],
+    loglevel => info,
+    # Another Semaphor for all packages to reference
+    alias => "apt_updated"
+  }
+
+}
index 7656a9b477ea273ca2640594b19166be4dae35e9..9f280c6489048ca4f406ecb1fe03fa29790d1b67 100644 (file)
@@ -1,15 +1,16 @@
 define apt::upgrade_package ($version = "") {
 
-  case $version {
-    '', 'latest': {
-      exec { "/usr/bin/apt-get update && aptitude -y install $name":
-        onlyif => [ "grep-status -F Status installed -a -P $name -q", "apt-show-versions -u $name | grep -q upgradeable" ],
-      }
-    }
-    default: {
-      exec { "/usr/bin/apt-get update && aptitude -y install $name=$version":
-        onlyif => [ "grep-status -F Status installed -a -P $name -q", "apt-show-versions -u $name | grep -q upgradeable" ],
-      }
-    }
+  include apt::update
+
+  $version_suffix = $version ? {
+    ''       => '',
+    'latest' => '',
+    default  => "=${version}",
+  }
+
+  exec { "aptitude -y install ${name}${version_suffix}":
+    onlyif => [ "grep-status -F Status installed -a -P $name -q", "apt-show-versions -u $name | grep -q upgradeable" ],
+    require => Exec['apt_updated'],
   }
+
 }