Merge pull request #466 from paroga/master
[puppet-modules/puppetlabs-apt.git] / manifests / ppa.pp
index 8a3b6f5f594e136113d697f5e89e73eeb61213f0..e86a19fd9d32216f1c1f3a85a0e3f04fb050cb2e 100644 (file)
@@ -1,9 +1,11 @@
 # ppa.pp
 
 define apt::ppa(
-  $ensure  = 'present',
-  $release = $::lsbdistcodename,
-  $options = $apt::params::ppa_options,
+  $ensure         = 'present',
+  $release        = $::lsbdistcodename,
+  $options        = $::apt::params::ppa_options,
+  $package_name   = $::apt::params::ppa_package,
+  $package_manage = true,
 ) {
   include apt::params
   include apt::update
@@ -15,7 +17,7 @@ define apt::ppa(
   }
 
   if $::operatingsystem != 'Ubuntu' {
-    fail("apt::ppa is currently supported on Ubuntu only.")
+    fail('apt::ppa is currently supported on Ubuntu only.')
   }
 
   $filename_without_slashes = regsubst($name, '/', '-', 'G')
@@ -24,53 +26,48 @@ define apt::ppa(
   $sources_list_d_filename  = "${filename_without_ppa}-${release}.list"
 
   if $ensure == 'present' {
-    $package = $::lsbdistrelease ? {
-        /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
-        default  => 'software-properties-common',
-    }
+    if $package_manage {
+      if ! defined(Package[$package_name]) {
+        package { $package_name: }
+      }
 
-    if ! defined(Package[$package]) {
-        package { $package: }
+      $_require = [File['sources.list.d'], Package[$package_name]]
+    } else {
+      $_require = File['sources.list.d']
     }
 
-    if defined(Class[apt]) {
-        $proxy_host = $apt::proxy_host
-        $proxy_port = $apt::proxy_port
-        case  $proxy_host {
-        false, '': {
-            $proxy_env = []
+    if defined(Class['apt']) {
+      case $::apt::proxy_host {
+        false, '', undef: {
+          $proxy_env = []
         }
-        default: {$proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"]}
+        default: {
+          $proxy_env = ["http_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}", "https_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}"]
         }
+      }
     } else {
-        $proxy_env = []
+      $proxy_env = []
     }
+
     exec { "add-apt-repository-${name}":
-        environment  => $proxy_env,
-        command      => "/usr/bin/add-apt-repository ${options} ${name}",
-        unless       => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}",
-        user         => 'root',
-        logoutput    => 'on_failure',
-        notify       => Exec['apt_update'],
-        require      => [
-        File['sources.list.d'],
-        Package[$package],
-        ],
+      environment => $proxy_env,
+      command     => "/usr/bin/add-apt-repository ${options} ${name}",
+      unless      => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}",
+      user        => 'root',
+      logoutput   => 'on_failure',
+      notify      => Exec['apt_update'],
+      require     => $_require,
     }
 
     file { "${sources_list_d}/${sources_list_d_filename}":
-        ensure  => file,
-        require => Exec["add-apt-repository-${name}"],
+      ensure  => file,
+      require => Exec["add-apt-repository-${name}"],
     }
   }
   else {
-
     file { "${sources_list_d}/${sources_list_d_filename}":
-        ensure => 'absent',
-        mode   => '0644',
-        owner  => 'root',
-        gruop  => 'root',
-        notify => Exec['apt_update'],
+      ensure => 'absent',
+      notify => Exec['apt_update'],
     }
   }