Merge pull request #1011 from Conzar/ppa-ubuntu-fix
[puppet-modules/puppetlabs-apt.git] / manifests / init.pp
index fcfb09c30de2ba94bdb25498747856aab2920210..2f82b7d8fdb40f374552f1a15b57006f9f8cb49f 100644 (file)
@@ -153,12 +153,19 @@ class apt (
   String $preferences_d         = $apt::params::preferences_d,
   String $apt_conf_d            = $apt::params::apt_conf_d,
   Hash $config_files            = $apt::params::config_files,
-  Hash $source_key_defaults     = $apt::params::source_key_defaults,
   Boolean $sources_list_force   = $apt::params::sources_list_force,
+
+  Hash $source_key_defaults = {
+    'server'  => $keyserver,
+    'options' => undef,
+    'content' => undef,
+    'source'  => undef,
+  }
+
 ) inherits apt::params {
 
-  if $facts['osfamily'] != 'Debian' {
-    fail(translate('This module only works on Debian or derivatives like Ubuntu'))
+  if $facts['os']['family'] != 'Debian' {
+    fail('This module only works on Debian or derivatives like Ubuntu')
   }
 
   if $update['frequency'] {
@@ -197,7 +204,29 @@ class apt (
   }
 
   $_purge = merge($::apt::purge_defaults, $purge)
-  $_proxy = merge($apt::proxy_defaults, $proxy)
+
+  if $proxy['perhost'] {
+    $_perhost = $proxy['perhost'].map |$item| {
+      $_item = merge($apt::proxy_defaults, $item)
+      $_scheme = $_item['https'] ? {
+        true    => 'https',
+        default => 'http' }
+      $_port = $_item['port'] ? {
+        Integer => ":${_item['port']}",
+        default => ''
+      }
+      $_target = $_item['direct'] ? {
+        true    => 'DIRECT',
+        default => "${_scheme}://${_item['host']}${_port}/" }
+      merge($item, {
+        'scheme' => $_scheme,
+        'target' => $_target })
+    }
+  } else {
+    $_perhost = {}
+  }
+
+  $_proxy = merge($apt::proxy_defaults, $proxy, { 'perhost' => $_perhost } )
 
   $confheadertmp = epp('apt/_conf_header.epp')
   $proxytmp = epp('apt/proxy.epp', {'proxies' => $_proxy})
@@ -238,12 +267,6 @@ class apt (
     default => file,
   }
 
-  if $_update['frequency'] == 'always' {
-    Exec <| title=='apt_update' |> {
-      refreshonly => false,
-    }
-  }
-
   apt::setting { 'conf-update-stamp':
     priority => 15,
     content  => "${confheadertmp}${updatestamptmp}",
@@ -329,7 +352,7 @@ class apt (
       owner   => $auth_conf_owner,
       group   => 'root',
       mode    => '0600',
-      content => "${confheadertmp}${auth_conf_tmp}",
+      content => Sensitive("${confheadertmp}${auth_conf_tmp}"),
       notify  => Class['apt::update'],
     }
   }