From a02654e36ca0cec2fa8360d0f52d34801df9229a Mon Sep 17 00:00:00 2001 From: Philipp Wagner Date: Wed, 3 Feb 2016 17:13:46 +0100 Subject: [PATCH] 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 --- manifests/ppa.pp | 18 +++++++++++++----- spec/classes/apt_spec.rb | 1 + spec/defines/ppa_spec.rb | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/manifests/ppa.pp b/manifests/ppa.pp index b83500b..7069e2e 100644 --- a/manifests/ppa.pp +++ b/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 { diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index 5aded56..cc2264b 100644 --- a/spec/classes/apt_spec.rb +++ b/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 diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 1e7e23a..74b52ea 100644 --- a/spec/defines/ppa_spec.rb +++ b/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": }' -- 2.32.3