(#11966) Only invoke apt-get update once.
[puppet-modules/puppetlabs-apt.git] / manifests / init.pp
index 7d243edd7b947369f0334f096a4d8f98c08b2688..ce88c3bd83814f575399972fa573463179ad1a77 100644 (file)
@@ -29,14 +29,10 @@ class apt(
 ) {
 
   include apt::params
+  include apt::update
 
   validate_bool($purge_sources_list, $purge_sources_list_d)
 
-  $refresh_only_apt_update = $always_apt_update? {
-    true  => false,
-    false => true,
-  }
-
   if ! defined(Package['python-software-properties']) {
     package { 'python-software-properties': }
   }
@@ -46,6 +42,12 @@ class apt(
     true  => "# Repos managed by puppet.\n",
   }
 
+  if $always_apt_update == true {
+    Exec <| title=='apt update' |> {
+      refreshonly => false,
+    }
+  }
+
   $root           = $apt::params::root
   $apt_conf_d     = $apt::params::apt_conf_d
   $sources_list_d = $apt::params::sources_list_d
@@ -58,6 +60,7 @@ class apt(
     group   => root,
     mode    => '0644',
     content => $sources_list_content,
+    notify  => Exec['apt update'],
   }
 
   file { 'sources.list.d':
@@ -67,12 +70,7 @@ class apt(
     group   => root,
     purge   => $purge_sources_list_d,
     recurse => $purge_sources_list_d,
-  }
-
-  exec { 'apt_update':
-    command     => "${provider} update",
-    subscribe   => [ File['sources.list'], File['sources.list.d'] ],
-    refreshonly => $refresh_only_apt_update,
+    notify  => Exec['apt update'],
   }
 
   case $disable_keys {
@@ -89,7 +87,7 @@ class apt(
         path   => "${apt_conf_d}/99unauth",
       }
     }
-    undef: { } # do nothing
+    undef:   { } # do nothing
     default: { fail('Valid values for disable_keys are true or false') }
   }
 
@@ -97,7 +95,7 @@ class apt(
     file { 'configure-apt-proxy':
       path    => "${apt_conf_d}/proxy",
       content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
-      notify  => Exec['apt_update'],
+      notify  => Exec['apt update'],
     }
   }
 }