# @param config_files
# A hash made up of the various configuration files used by Apt.
#
+# @param sources_list_force
+# Specifies whether to perform force purge or delete. Default false.
+#
class apt (
Hash $update_defaults = $apt::params::update_defaults,
Hash $purge_defaults = $apt::params::purge_defaults,
String $apt_conf_d = $apt::params::apt_conf_d,
Hash $config_files = $apt::params::config_files,
Hash $source_key_defaults = $apt::params::source_key_defaults,
+ Boolean $sources_list_force = $apt::params::sources_list_force,
) inherits apt::params {
if $facts['osfamily'] != 'Debian' {
if $purge['preferences.d'] {
assert_type(Boolean, $purge['preferences.d'])
}
+ if $sources_list_force {
+ assert_type(Boolean, $sources_list_force)
+ }
if $purge['apt.conf.d'] {
assert_type(Boolean, $purge['apt.conf.d'])
}
}
}
- $sources_list_ensure = $_purge['sources.list'] ? {
- true => absent,
- default => file,
+ if $sources_list_force {
+ $sources_list_ensure = $_purge['sources.list'] ? {
+ true => absent,
+ default => file,
+ }
+ $sources_list_content = $_purge['sources.list'] ? {
+ true => nil,
+ default => undef,
+ }
}
+ else
+ {
+ $sources_list_ensure = $_purge['sources.list'] ? {
+ true => file,
+ default => file,
+ }
+ $sources_list_content = $_purge['sources.list'] ? {
+ true => "# Repos managed by puppet.\n",
+ default => undef,
+ }
+ }
$preferences_ensure = $_purge['preferences'] ? {
true => absent,
}
file { 'sources.list':
- ensure => $sources_list_ensure,
- path => $::apt::sources_list,
- owner => root,
- group => root,
- notify => Class['apt::update'],
+ ensure => $sources_list_ensure,
+ path => $::apt::sources_list,
+ owner => root,
+ group => root,
+ content => $sources_list_content,
+ notify => Class['apt::update'],
}
file { 'sources.list.d':
fail(translate('This module only works on Debian or derivatives like Ubuntu'))
}
- $root = '/etc/apt'
- $provider = '/usr/bin/apt-get'
- $sources_list = "${root}/sources.list"
- $sources_list_d = "${root}/sources.list.d"
- $trusted_gpg_d = "${root}/trusted.gpg.d"
- $conf_d = "${root}/apt.conf.d"
- $preferences = "${root}/preferences"
- $preferences_d = "${root}/preferences.d"
- $apt_conf_d = "${root}/apt.conf.d"
- $keyserver = 'keyserver.ubuntu.com'
- $key_options = undef
- $confs = {}
- $update = {}
- $purge = {}
- $proxy = {}
- $sources = {}
- $keys = {}
- $ppas = {}
- $pins = {}
- $settings = {}
- $manage_auth_conf = true
- $auth_conf_entries = []
+ $root = '/etc/apt'
+ $provider = '/usr/bin/apt-get'
+ $sources_list = "${root}/sources.list"
+ $sources_list_force = false
+ $sources_list_d = "${root}/sources.list.d"
+ $trusted_gpg_d = "${root}/trusted.gpg.d"
+ $conf_d = "${root}/apt.conf.d"
+ $preferences = "${root}/preferences"
+ $preferences_d = "${root}/preferences.d"
+ $apt_conf_d = "${root}/apt.conf.d"
+ $keyserver = 'keyserver.ubuntu.com'
+ $key_options = undef
+ $confs = {}
+ $update = {}
+ $purge = {}
+ $proxy = {}
+ $sources = {}
+ $keys = {}
+ $ppas = {}
+ $pins = {}
+ $settings = {}
+ $manage_auth_conf = true
+ $auth_conf_entries = []
$config_files = {
'conf' => {
}
end
+ context 'with lots of non-defaults' do
+ let :params do
+ {
+ update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+ purge: { 'sources.list' => true, 'sources.list.d' => true,
+ 'preferences' => true, 'preferences.d' => true,
+ 'apt.conf.d' => true },
+ }
+ end
+
+ it {
+ is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
+ }
+
+ it {
+ is_expected.to contain_file('sources.list.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ is_expected.to contain_file('preferences').with(ensure: 'absent')
+ }
+
+ it {
+ is_expected.to contain_file('preferences.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ is_expected.to contain_file('apt.conf.d').with(purge: true,
+ recurse: true)
+ }
+
+ it {
+ is_expected.to contain_exec('apt_update').with(refreshonly: false,
+ timeout: 1,
+ tries: 3)
+ }
+ end
+
+ context 'with defaults for sources_list_force' do
+ let :params do
+ {
+ update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+ purge: { 'sources.list' => true },
+ sources_list_force: false,
+ }
+ end
+
+ it {
+ is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
+ }
+ end
+
+ context 'with non defaults for sources_list_force' do
+ let :params do
+ {
+ update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
+ purge: { 'sources.list' => true },
+ sources_list_force: true,
+ }
+ end
+
+ it {
+ is_expected.to contain_file('sources.list').with(ensure: 'absent')
+ }
+ end
+
context 'with entries for /etc/apt/auth.conf' do
facts_hash = {
'Ubuntu 14.04' => {