Make installation of software-properties optional
This is cherry-picked from the PPA cleanup happening for the 2.0.0 release. Conflicts: manifests/params.pp manifests/ppa.pp
This commit is contained in:
parent
b473af1ec5
commit
0c35704245
4 changed files with 127 additions and 39 deletions
|
@ -332,6 +332,14 @@ apt::sources:
|
||||||
|
|
||||||
It is recommended to read the manpage 'apt_preferences(5)'
|
It is recommended to read the manpage 'apt_preferences(5)'
|
||||||
|
|
||||||
|
####apt::ppa
|
||||||
|
|
||||||
|
* `ensure`: Whether we are adding or removing the PPA. Can be 'present' or 'absent'. Defaults to 'present'.
|
||||||
|
* `release`: The codename for the operating system you're running. Defaults to `$lsbdistcodename`. Required if lsb-release is not installed.
|
||||||
|
* `options`: Options to be passed to the `apt-add-repository` command. OS-dependent defaults are set in `apt::params`.
|
||||||
|
* `package_name`: The package that provides the `apt-add-repository` command. OS-dependent defaults are set in `apt::params`.
|
||||||
|
* `package_manage`: Whether or not to manage the package providing `apt-add-repository`. Defaults to true.
|
||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
|
|
||||||
The apt module is mostly a collection of defined resource types, which provide reusable logic for managing Apt. It provides smoke tests for testing functionality on a target system, as well as spec tests for checking a compiled catalog against an expected set of resources.
|
The apt module is mostly a collection of defined resource types, which provide reusable logic for managing Apt. It provides smoke tests for testing functionality on a target system, as well as spec tests for checking a compiled catalog against an expected set of resources.
|
||||||
|
|
|
@ -64,18 +64,28 @@ class apt::params {
|
||||||
'lucid': {
|
'lucid': {
|
||||||
$backports_location = 'http://us.archive.ubuntu.com/ubuntu'
|
$backports_location = 'http://us.archive.ubuntu.com/ubuntu'
|
||||||
$ppa_options = undef
|
$ppa_options = undef
|
||||||
|
$ppa_package = 'python-software-properties'
|
||||||
$legacy_origin = true
|
$legacy_origin = true
|
||||||
$origins = ['${distro_id} ${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables
|
$origins = ['${distro_id} ${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables
|
||||||
}
|
}
|
||||||
'precise', 'trusty', 'utopic', 'vivid': {
|
'precise': {
|
||||||
$backports_location = 'http://us.archive.ubuntu.com/ubuntu'
|
$backports_location = 'http://us.archive.ubuntu.com/ubuntu'
|
||||||
$ppa_options = '-y'
|
$ppa_options = '-y'
|
||||||
|
$ppa_package = 'python-software-properties'
|
||||||
|
$legacy_origin = true
|
||||||
|
$origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables
|
||||||
|
}
|
||||||
|
'trusty', 'utopic', 'vivid': {
|
||||||
|
$backports_location = 'http://us.archive.ubuntu.com/ubuntu'
|
||||||
|
$ppa_options = '-y'
|
||||||
|
$ppa_package = 'software-properties-common'
|
||||||
$legacy_origin = true
|
$legacy_origin = true
|
||||||
$origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables
|
$origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
$backports_location = 'http://old-releases.ubuntu.com/ubuntu'
|
$backports_location = 'http://old-releases.ubuntu.com/ubuntu'
|
||||||
$ppa_options = '-y'
|
$ppa_options = '-y'
|
||||||
|
$ppa_package = 'python-software-properties'
|
||||||
$legacy_origin = true
|
$legacy_origin = true
|
||||||
$origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables
|
$origins = ['${distro_id}:${distro_codename}-security'] #lint:ignore:single_quote_string_with_variables
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
define apt::ppa(
|
define apt::ppa(
|
||||||
$ensure = 'present',
|
$ensure = 'present',
|
||||||
$release = $::lsbdistcodename,
|
$release = $::lsbdistcodename,
|
||||||
$options = $apt::params::ppa_options,
|
$options = $::apt::params::ppa_options,
|
||||||
|
$package_name = $::apt::params::ppa_package,
|
||||||
|
$package_manage = true,
|
||||||
) {
|
) {
|
||||||
include apt::params
|
include apt::params
|
||||||
include apt::update
|
include apt::update
|
||||||
|
@ -24,29 +26,29 @@ 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',
|
if ! defined(Package[$package_name]) {
|
||||||
default => 'software-properties-common',
|
package { $package_name: }
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! defined(Package[$package]) {
|
$_require = [File['sources.list.d'], Package[$package_name]]
|
||||||
package { $package: }
|
} else {
|
||||||
|
$_require = File['sources.list.d']
|
||||||
}
|
}
|
||||||
|
|
||||||
if defined(Class[apt]) {
|
if defined(Class['apt']) {
|
||||||
$proxy_host = $apt::proxy_host
|
case $::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 {
|
} else {
|
||||||
$proxy_env = []
|
$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}",
|
||||||
|
@ -54,10 +56,7 @@ define apt::ppa(
|
||||||
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 { "${sources_list_d}/${sources_list_d_filename}":
|
file { "${sources_list_d}/${sources_list_d_filename}":
|
||||||
|
@ -66,7 +65,6 @@ define apt::ppa(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
file { "${sources_list_d}/${sources_list_d_filename}":
|
file { "${sources_list_d}/${sources_list_d_filename}":
|
||||||
ensure => 'absent',
|
ensure => 'absent',
|
||||||
notify => Exec['apt_update'],
|
notify => Exec['apt_update'],
|
||||||
|
|
|
@ -32,6 +32,78 @@ describe 'apt::ppa', :type => :define do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'package_name => software-properties-common' do
|
||||||
|
let :pre_condition do
|
||||||
|
'class { "apt": }'
|
||||||
|
end
|
||||||
|
let :params do
|
||||||
|
{
|
||||||
|
:package_name => 'software-properties-common'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:lsbdistrelease => '11.04',
|
||||||
|
:lsbdistcodename => 'natty',
|
||||||
|
:operatingsystem => 'Ubuntu',
|
||||||
|
:osfamily => 'Debian',
|
||||||
|
:lsbdistid => 'Ubuntu',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:title) { 'ppa:needs/such.substitution/wow' }
|
||||||
|
it { is_expected.to contain_package('software-properties-common') }
|
||||||
|
it { is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Exec[apt_update]').with({
|
||||||
|
'environment' => [],
|
||||||
|
'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
|
||||||
|
'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
|
||||||
|
'user' => 'root',
|
||||||
|
'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
|
||||||
|
|
||||||
|
describe 'package_manage => false' do
|
||||||
|
let :pre_condition do
|
||||||
|
'class { "apt": }'
|
||||||
|
end
|
||||||
|
let :facts do
|
||||||
|
{
|
||||||
|
:lsbdistrelease => '11.04',
|
||||||
|
:lsbdistcodename => 'natty',
|
||||||
|
:operatingsystem => 'Ubuntu',
|
||||||
|
:osfamily => 'Debian',
|
||||||
|
:lsbdistid => 'Ubuntu',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let :params do
|
||||||
|
{
|
||||||
|
:package_manage => false,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:title) { 'ppa:needs/such.substitution/wow' }
|
||||||
|
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({
|
||||||
|
'environment' => [],
|
||||||
|
'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow',
|
||||||
|
'unless' => '/usr/bin/test -s /etc/apt/sources.list.d/needs-such_substitution-wow-natty.list',
|
||||||
|
'user' => 'root',
|
||||||
|
'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
|
||||||
|
|
||||||
describe 'apt included, no proxy' do
|
describe 'apt included, no proxy' do
|
||||||
let :pre_condition do
|
let :pre_condition do
|
||||||
'class { "apt": }'
|
'class { "apt": }'
|
||||||
|
|
Loading…
Reference in a new issue