(#14657) Fix filename when there is a period in the PPA
[puppet-modules/puppetlabs-apt.git] / manifests / ppa.pp
index 2821051a9902d4d85e89791e85f2d69bdd781cac..6b38e52d63164b8249adea6e2b5142829c54050d 100644 (file)
@@ -1,20 +1,42 @@
 # ppa.pp
 
 define apt::ppa(
-
+  $release = $::lsbdistcodename
 ) {
-       include apt
+  include apt::params
+  include apt::update
+
+  $sources_list_d = $apt::params::sources_list_d
+
+  if ! $release {
+    fail('lsbdistcodename fact not available: release parameter required')
+  }
+
+  $filename_without_slashes = regsubst($name, '/', '-', G)
+  $filename_without_dots    = regsubst($filename_without_slashes, '\.', '_', G)
+  $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 { "python-software-properties": }
+  exec { "add-apt-repository-${name}":
+    command => "/usr/bin/add-apt-repository ${name}",
+    creates => "${sources_list_d}/${sources_list_d_filename}",
+    require => [ File[$sources_list_d],
+                 Package['python-software-properties'] ],
+    notify  => Exec['apt_update'],
+  }
 
-    exec { "apt-update":
-        command     => "/usr/bin/apt-get update",
-        refreshonly => true,
-    }
+  file { "${sources_list_d}/${sources_list_d_filename}":
+    ensure  => file,
+    require => Exec["add-apt-repository-${name}"],
+  }
 
-    exec { "/usr/bin/add-apt-repository ${name}":
-        require => Package["python-software-properties"],
-        notify => Exec["apt-update"]
-    }
+  # Need anchor to provide containment for dependencies.
+  anchor { "apt::ppa::${name}":
+    require => Class['apt::update'],
+  }
 }