add .pref extension, which according to apt_preferences(5) may or may not be present...
[puppet-modules/puppetlabs-apt.git] / manifests / ppa.pp
index af6eebff0a4064ec35a52d178a570c4222b41609..64c65bbd09e41d595b902135d6fd5222138fb114 100644 (file)
@@ -1,24 +1,41 @@
 # ppa.pp
 
-define apt::ppa() {
+define apt::ppa(
+  $release = $::lsbdistcodename
+) {
+  include apt::params
+  include apt::update
 
-  Class['apt'] -> Apt::Ppa[$title]
+  $sources_list_d = $apt::params::sources_list_d
 
-  Exec {
-    unless => $name? {
-      /ppa:(.*)/ => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*ppa.*$1.*$'",
-      default    => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*${title}.*$'",
-    }
+  if ! $release {
+    fail('lsbdistcodename fact not available: release parameter required')
   }
 
-  exec { "apt-update-${name}":
-    command     => "/usr/bin/aptitude update",
-    refreshonly => true,
+  $filename_without_slashes = regsubst($name,'/','-','G')
+  $filename_without_ppa     = regsubst($filename_without_slashes, '^ppa:','','G')
+  $sources_list_d_filename  = "${filename_without_ppa}-${release}.list"
+
+  if ! defined(Package['python-software-properties']) {
+    package { 'python-software-properties': }
   }
 
   exec { "add-apt-repository-${name}":
     command => "/usr/bin/add-apt-repository ${name}",
-    notify  => Exec["apt-update-${name}"],
+    creates => "${sources_list_d}/${sources_list_d_filename}",
+    require => [ File[$sources_list_d],
+                 Package['python-software-properties'] ],
+    notify  => Exec['apt_update'],
+  }
+
+  file { "${sources_list_d}/${sources_list_d_filename}":
+    ensure  => file,
+    require => Exec["add-apt-repository-${name}"],
+  }
+
+  # Need anchor to provide containment for dependencies.
+  anchor { "apt::ppa::${name}":
+    require => Class['apt::update'],
   }
 }