]> gitweb.fluxo.info Git - puppet-apt.git/commitdiff
[refactor] Unify `apt-get update` into one resource
authorvarac <varacanero@zeromail.org>
Tue, 26 Jan 2016 13:42:17 +0000 (14:42 +0100)
committervarac <varacanero@zeromail.org>
Mon, 1 Feb 2016 19:25:46 +0000 (20:25 +0100)
Before, there were two Execs that did an `apt-get update`,
`Exec[refresh_apt]` and `Exec[apt_updated]`, which were triggered
by different resources.
This changes gets rid of the first one, and all resources now depend
on `Exec[apt_updated]`.

README
manifests/apt_conf.pp
manifests/dist_upgrade.pp
manifests/dot_d_directories.pp
manifests/init.pp
manifests/key.pp
manifests/key/plain.pp
manifests/preferences_snippet.pp
manifests/sources_list.pp
manifests/update.pp

diff --git a/README b/README
index 410201dcb60189a5fdf1e4254c84aa09b63dd1d2..e097a7e9eba05d8523fec2053679447659575b07 100644 (file)
--- a/README
+++ b/README
@@ -17,6 +17,14 @@ Ubuntu support is lagging behind but not absent either.
 
 ! Upgrade Notice !
 
+ * The `disable_update` parameter has been removed. The main apt class
+   defaults to *not* run an `apt-get update` on every run anyway so this
+   parameter seems useless.
+   You can include the `apt::update` class if you want it to be run every time.
+
+ * The `apt::upgrade_package` now doesn't automatically call an Exec['apt_updated']
+   anymore, so you would need to include `apt::update` now by hand.
+
  * The apt::codename parameter has been removed. In its place, the
    debian_codename fact may be overridden via an environment variable. This
    will affect all other debian_* facts, and achieve the same result.
@@ -188,15 +196,6 @@ Class parameters:
   If this variable is set the default repositories list ("main contrib non-free")
   is overriden.
 
-* disable_update
-
-  Disable "apt-get update" which is normally triggered by apt::upgrade_package 
-  and apt::dist_upgrade. 
-
-  Note that nodes can be updated once a day by using 
-    APT::Periodic::Update-Package-Lists "1";
-  in i.e. /etc/apt/apt.conf.d/80_apt_update_daily.
-
 * custom_preferences
 
   For historical reasons (Debian Lenny's version of APT did not support the use
@@ -296,9 +295,6 @@ classes may inherit from this one and add to its subscription list
 using the plusignment ('+>') operator. A real-world example can be
 seen in the apt::dist_upgrade::initiator source.
 
-When this class is included the APT indexes are updated on every
-Puppet run due to the author's lack of Puppet wizardry.
-
 apt::dist_upgrade::initiator
 ----------------------------
 
@@ -555,18 +551,22 @@ Exec['apt_updated']
 -------------------
 
 After this point the APT indexes are up-to-date.
+This resource is set to `refreshonly => true` so it is not run on
+every puppetrun. To run this every time, you can include the `apt::update`
+class.
 
 This resource is usually used like this to ensure current packages are
 installed by Package resources:
 
-  include apt::update
-  Package { require => Exec['apt_updated'] }
+    include apt::update
+    Package { require => Exec['apt_updated'] }
+
+Note that nodes can be updated once a day by using
+
+    APT::Periodic::Update-Package-Lists "1";
+
+in i.e. /etc/apt/apt.conf.d/80_apt_update_daily.
 
-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.
 
 Tests
 =====
index f446c694c512b5499ebebf98b7f9de291111305d..949f6157ccfd4720d0b7ea8badc8ce354100aeaa 100644 (file)
@@ -38,7 +38,7 @@ define apt::apt_conf(
 
   if $refresh_apt {
     File["/etc/apt/apt.conf.d/${name}"] {
-      notify => Exec['refresh_apt'],
+      notify => Exec['apt_updated'],
     }
   }
 
index bf78dcca46a7125561a125ded820466b4842fd70..19c031e0136124c85b5cffa7adc87cfa162346da 100644 (file)
@@ -1,18 +1,9 @@
 class apt::dist_upgrade {
 
-  if $apt::disable_update == false {
-    include apt::update
-  }
-
-  $req = $apt::disable_update ? {
-    true    => undef,
-    default => Exec['apt_updated'],
-  }
-
   exec { 'apt_dist-upgrade':
     command     => '/usr/bin/apt-get -q -y -o \'DPkg::Options::=--force-confold\' dist-upgrade',
     refreshonly => true,
-    require     => $req
+    before      => Exec['apt_updated']
   }
 
 }
index 37c3fc8597bf749019185747da830a9d3fc96663..0ace86302cd0be680a2996119189e4485a2c0c0b 100644 (file)
@@ -5,18 +5,11 @@ class apt::dot_d_directories {
     '/etc/apt/apt.conf.d':
       ensure   => directory,
       checksum => mtime,
-      notify   => Exec['refresh_apt'];
+      notify   => Exec['apt_updated'];
     '/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,
+      notify   => Exec['apt_updated'];
   }
 
 }
index 1e7ddd7f70752138e24ea74a3a4c74d941eb9a96..f9f935757fc99d2fa51c4a37c197cc8e5ca165df 100644 (file)
@@ -50,7 +50,7 @@ class apt(
     # additional sources should be included via the apt::sources_list define
     '/etc/apt/sources.list':
       content => $sources_content,
-      notify  => Exec['refresh_apt'],
+      notify  => Exec['apt_updated'],
       owner   => root,
       group   => 0,
       mode    => '0644';
@@ -137,4 +137,16 @@ class apt(
 
   # workaround for preseeded_package component
   file { [ '/var/cache', '/var/cache/local', '/var/cache/local/preseeding' ]: ensure => directory }
+
+  exec { 'update_apt':
+    command     => '/usr/bin/apt-get update && /usr/bin/apt-get autoclean',
+    require     => [
+      File['/etc/apt/apt.conf.d', '/etc/apt/preferences' ],
+      File['/etc/apt/sources.list'] ],
+    loglevel    => 'info',
+    refreshonly => true,
+    # Another Semaphor for all packages to reference
+    alias       => [ 'apt_updated', 'refresh_apt']
+  }
+
 }
index 65b62e93fc0212f506b4b94cc4e6390ba40ad1d0..cb70ec6acf801f3a71b7e5151181a573daff2084 100644 (file)
@@ -8,6 +8,6 @@ define apt::key ($source, $ensure = 'present') {
     "/etc/apt/trusted.gpg.d/${name}":
       ensure => $ensure,
       source => $source,
-      notify => Exec['refresh_apt'],
+      notify => Exec['apt_updated'],
   }
 }
index e4a2f899fa5e15fc0856e14cac0362a382ae328d..dff8b51b8603bf0572ead5cc8e7ed2f523c98add 100644 (file)
@@ -8,6 +8,6 @@ define apt::key::plain ($source) {
   exec { "apt-key add '${apt::apt_base_dir}/keys/${name}'":
     subscribe   => File["${apt::apt_base_dir}/keys/${name}"],
     refreshonly => true,
-    notify      => Exec['refresh_apt'],
+    notify      => Exec['apt_updated'],
   }
 }
index 99feac4e627ea409e329965500e7b3011277f2c1..b7dba0d82b1a916fc0fcfa38dab9e985e6cd641e 100644 (file)
@@ -32,7 +32,7 @@ define apt::preferences_snippet (
   file { "/etc/apt/preferences.d/${name}":
     ensure => $ensure,
     owner  => root, group => 0, mode => '0644',
-    before => Exec['refresh_apt'];
+    before => Exec['apt_updated'];
   }
 
   case $source {
index aefad2d8de9dbc0a098e21442f8de8aa408c62e9..0ee068d1a36083c97746f4897d486588155e72c1 100644 (file)
@@ -23,7 +23,7 @@ define apt::sources_list (
   file { "/etc/apt/sources.list.d/${realname}.list":
     ensure => $ensure,
     owner  => root, group => 0, mode => '0644',
-    notify => Exec['refresh_apt'],
+    notify => Exec['apt_updated'],
   }
 
   if $source {
index 3f451251fdba2ee5fcd5f295709ee26ccd41a54a..dde83200f161262ac74527bc73198e644c8bde93 100644 (file)
@@ -1,13 +1,7 @@
-class apt::update {
+class apt::update inherits ::apt {
 
-  exec { 'update_apt':
-    command => '/usr/bin/apt-get update && /usr/bin/apt-get autoclean',
-    require => [
-                File['/etc/apt/apt.conf.d', '/etc/apt/preferences' ],
-                File['/etc/apt/sources.list'] ],
-    loglevel => info,
-    # Another Semaphor for all packages to reference
-    alias => 'apt_updated'
+  Exec['update_apt'] {
+    refreshonly => false
   }
 
 }