Merge pull request #433 from mhaskel/ppa

PPA Cleanup, pt 1
This commit is contained in:
Daniele Sluijters 2015-02-23 20:21:10 +01:00
commit cddf5498f0
3 changed files with 40 additions and 51 deletions

View file

@ -64,12 +64,19 @@ class apt::params {
case $distcodename { case $distcodename {
'lucid': { 'lucid': {
$ppa_options = undef $ppa_options = undef
$ppa_package = 'python-software-properties'
} }
'precise', 'trusty', 'utopic', 'vivid': { 'precise': {
$ppa_options = '-y' $ppa_options = '-y'
$ppa_package = 'python-software-properties'
}
'trusty', 'utopic', 'vivid': {
$ppa_options = '-y'
$ppa_package = 'software-properties-common'
} }
default: { default: {
$ppa_options = '-y' $ppa_options = '-y'
$ppa_package = 'software-properties-common'
} }
} }
} }

View file

@ -3,8 +3,9 @@ define apt::ppa(
$ensure = 'present', $ensure = 'present',
$release = $::lsbdistcodename, $release = $::lsbdistcodename,
$options = $::apt::ppa_options, $options = $::apt::ppa_options,
$package_name = $::apt::ppa_package,
$package_manage = false,
) { ) {
if ! $release { if ! $release {
fail('lsbdistcodename fact not available: release parameter required') fail('lsbdistcodename fact not available: release parameter required')
} }
@ -19,40 +20,31 @@ define apt::ppa(
$sources_list_d_filename = "${filename_without_ppa}-${release}.list" $sources_list_d_filename = "${filename_without_ppa}-${release}.list"
if $ensure == 'present' { if $ensure == 'present' {
$package = $::lsbdistrelease ? { if $package_manage {
/^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties', package { $package_name: }
default => 'software-properties-common',
$_require = [File['sources.list.d'], Package[$package_name]]
} else {
$_require = File['sources.list.d']
} }
if ! defined(Package[$package]) { case $::apt::proxy_host {
package { $package: }
}
if defined(Class[apt]) {
$proxy_host = $apt::proxy_host
$proxy_port = $apt::proxy_port
case $proxy_host {
false, '', undef: { false, '', undef: {
$proxy_env = [] $_proxy_env = []
} }
default: { default: {
$proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"] $_proxy_env = ["http_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}", "https_proxy=http://${::apt::proxy_host}:${::apt::proxy_port}"]
} }
} }
} else {
$proxy_env = []
}
exec { "add-apt-repository-${name}": exec { "add-apt-repository-${name}":
environment => $proxy_env, environment => $_proxy_env,
command => "/usr/bin/add-apt-repository ${options} ${name}", command => "/usr/bin/add-apt-repository ${options} ${name}",
unless => "/usr/bin/test -s ${::apt::sources_list_d}/${sources_list_d_filename}", unless => "/usr/bin/test -s ${::apt::sources_list_d}/${sources_list_d_filename}",
user => 'root', user => 'root',
logoutput => 'on_failure', logoutput => 'on_failure',
notify => Exec['apt_update'], notify => Exec['apt_update'],
require => [ require => $_require,
File['sources.list.d'],
Package[$package],
],
} }
file { "${::apt::sources_list_d}/${sources_list_d_filename}": file { "${::apt::sources_list_d}/${sources_list_d_filename}":
@ -61,7 +53,6 @@ define apt::ppa(
} }
} }
else { else {
file { "${::apt::sources_list_d}/${sources_list_d_filename}": file { "${::apt::sources_list_d}/${sources_list_d_filename}":
ensure => 'absent', ensure => 'absent',
notify => Exec['apt_update'], notify => Exec['apt_update'],

View file

@ -16,7 +16,7 @@ describe 'apt::ppa', :type => :define do
end end
let(:title) { 'ppa:needs/such.substitution/wow' } let(:title) { 'ppa:needs/such.substitution/wow' }
it { is_expected.to contain_package('python-software-properties') } it { is_expected.to_not contain_package('python-software-properties') }
it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({ it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
'environment' => [], 'environment' => [],
'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', 'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
@ -25,11 +25,6 @@ describe 'apt::ppa', :type => :define do
'logoutput' => 'on_failure', 'logoutput' => 'on_failure',
}) })
} }
it { is_expected.to contain_file('/etc/apt/sources.list.d/needs-such_substitution-wow-natty.list').that_requires('Exec[add-apt-repository-ppa:needs/such.substitution/wow]').with({
'ensure' => 'file',
})
}
end end
describe 'apt included, no proxy' do describe 'apt included, no proxy' do
@ -48,6 +43,7 @@ describe 'apt::ppa', :type => :define do
let :params do let :params do
{ {
'options' => '', 'options' => '',
'package_manage' => true,
} }
end end
let(:title) { 'ppa:foo' } let(:title) { 'ppa:foo' }
@ -60,11 +56,6 @@ describe 'apt::ppa', :type => :define do
'logoutput' => 'on_failure', 'logoutput' => 'on_failure',
}) })
} }
it { is_expected.to contain_file('/etc/apt/sources.list.d/foo-trusty.list').that_requires('Exec[add-apt-repository-ppa:foo]').with({
'ensure' => 'file',
})
}
end end
describe 'ensure absent' do describe 'ensure absent' do