ppa: fix empty environment definition in exec ressource when no proxy
[puppet-modules/puppetlabs-apt.git] / manifests / ppa.pp
index 0458589849e30ec90dcc8f7a7d6f0d73ef6f3c32..6cb921f19bec95951ff52a554b0f8cb096f4ed39 100644 (file)
@@ -17,17 +17,35 @@ define apt::ppa(
   $filename_without_ppa     = regsubst($filename_without_dots, '^ppa:', '', G)
   $sources_list_d_filename  = "${filename_without_ppa}-${release}.list"
 
-  if ! defined(Package['python-software-properties']) {
-    package { 'python-software-properties': }
+  $package = $::lsbdistrelease ? {
+    /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
+    default  => 'software-properties-common',
   }
 
+  if ! defined(Package[$package]) {
+    package { $package: }
+  }
+
+  if defined(Class[apt]) {
+    $proxy_host = getparam(Class[apt], "proxy_host")
+    $proxy_port = getparam(Class[apt], "proxy_port")
+    case  $proxy_host {
+      false, "": {
+        $proxy_env = []
+      }
+      default: {$proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"]}
+    }
+  } else {
+    $proxy_env = []
+  }
   exec { "add-apt-repository-${name}":
+    environment  => $proxy_env,
     command   => "/usr/bin/add-apt-repository ${name}",
     creates   => "${sources_list_d}/${sources_list_d_filename}",
     logoutput => 'on_failure',
     require   => [
       File[$sources_list_d],
-      Package['python-software-properties'],
+      Package["${package}"],
     ],
     notify    => Exec['apt_update'],
   }
@@ -42,4 +60,3 @@ define apt::ppa(
     require => Class['apt::update'],
   }
 }
-