Przeglądaj źródła

Look for correct sources.list.d file for apt::ppa

In Ubuntu 15.10 the path of the apt sources file, which is generated by
apt-add-repository, changed to include the distid. This breaks apt::ppa
idempotency, since it does not recognize the repository is already
added.

Reported on puppet-users as well:
https://groups.google.com/forum/#!topic/puppet-users/YzeMyZYUo98
Philipp Wagner 8 lat temu
rodzic
commit
a02654e36c
3 zmienionych plików z 37 dodań i 5 usunięć
  1. 13 5
      manifests/ppa.pp
  2. 1 0
      spec/classes/apt_spec.rb
  3. 23 0
      spec/defines/ppa_spec.rb

+ 13 - 5
manifests/ppa.pp

@@ -14,11 +14,19 @@ define apt::ppa(
     fail('apt::ppa is not currently supported on Debian.')
   }
 
-  $filename_without_slashes = regsubst($name, '/', '-', 'G')
-  $filename_without_dots    = regsubst($filename_without_slashes, '\.', '_', 'G')
-  $filename_without_pluses  = regsubst($filename_without_dots, '\+', '_', 'G')
-  $filename_without_ppa     = regsubst($filename_without_pluses, '^ppa:', '', 'G')
-  $sources_list_d_filename  = "${filename_without_ppa}-${release}.list"
+  $ubuntu_release_year  = regsubst($::apt::xfacts['lsbdistrelease'], '\.\d+$', '', 'G') + 0
+  $ubuntu_release_month = regsubst($::apt::xfacts['lsbdistrelease'], '^\d+\.', '', 'G') + 0
+
+  if $ubuntu_release_year >= 15 and $ubuntu_release_month >= 10 {
+    $distid = downcase($::apt::xfacts['lsbdistid'])
+    $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}")
+  } else {
+    $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}")
+  }
+
+  $filename_no_slashes      = regsubst($filename, '/', '-', 'G')
+  $filename_no_specialchars = regsubst($filename_no_slashes, '[\.\+]', '_', 'G')
+  $sources_list_d_filename  = "${filename_no_specialchars}.list"
 
   if $ensure == 'present' {
     if $package_manage {

+ 1 - 0
spec/classes/apt_spec.rb

@@ -208,6 +208,7 @@ describe 'apt' do
       { :osfamily        => 'Debian',
         :lsbdistcodename => 'precise',
         :lsbdistid       => 'ubuntu',
+        :lsbdistrelease  => '12.04',
         :puppetversion   => Puppet.version,
       }
     end

+ 23 - 0
spec/defines/ppa_spec.rb

@@ -28,6 +28,29 @@ describe 'apt::ppa' do
     }
   end
 
+  describe 'Ubuntu 15.10 sources.list filename' do
+    let :facts do
+      {
+        :lsbdistrelease  => '15.10',
+        :lsbdistcodename => 'wily',
+        :operatingsystem => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistid       => 'Ubuntu',
+        :puppetversion   => Puppet.version,
+      }
+    end
+
+    let(:title) { 'ppa:user/foo' }
+    it { is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with({
+      :environment => [],
+      :command     => '/usr/bin/add-apt-repository -y ppa:user/foo',
+      :unless      => '/usr/bin/test -s /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
+      :user        => 'root',
+      :logoutput   => 'on_failure',
+    })
+    }
+  end
+
   describe 'ppa depending on ppa, MODULES-1156' do
     let :pre_condition do
       'class { "apt": }'