module-puppetlabs-apt/manifests/init.pp
Morgan Haskel 911c4de90f (MODULES-1156, MODULES-769) Remove unnecessary anchors
`apt::ppa` and `apt::setting` don't actually include `apt::update` so
anchors are unnecessary. Move `apt` to use contain instead of anchors,
since it wasn't anchoring properly anyways. Update the tests to make
sure it can have settings and ppas depending on each other without
cycles.
2015-03-24 18:18:14 -04:00

154 lines
3.4 KiB
Puppet

#
class apt(
$update = {},
$purge = {},
$proxy = {},
$sources = {},
$keys = {},
$ppas = {},
$settings = {},
) inherits ::apt::params {
$frequency_options = ['always','daily','weekly','reluctantly']
validate_hash($update)
if $update['frequency'] {
validate_re($update['frequency'], $frequency_options)
}
if $update['timeout'] {
unless is_integer($update['timeout']) {
fail('timeout value for update must be an integer')
}
}
if $update['tries'] {
unless is_integer($update['tries']) {
fail('tries value for update must be an integer')
}
}
$_update = merge($::apt::update_defaults, $update)
include apt::update
validate_hash($purge)
if $purge['sources.list'] {
validate_bool($purge['sources.list'])
}
if $purge['sources.list.d'] {
validate_bool($purge['sources.list.d'])
}
if $purge['preferences'] {
validate_bool($purge['preferences'])
}
if $purge['preferences.d'] {
validate_bool($purge['preferences.d'])
}
$_purge = merge($::apt::purge_defaults, $purge)
validate_hash($proxy)
if $proxy['host'] {
validate_string($proxy['host'])
}
if $proxy['port'] {
unless is_integer($proxy['port']) {
fail('$proxy port must be an integer')
}
}
if $proxy['https'] {
validate_bool($proxy['https'])
}
$_proxy = merge($apt::proxy_defaults, $proxy)
validate_hash($sources)
validate_hash($keys)
validate_hash($settings)
validate_hash($ppas)
if $proxy['host'] {
apt::setting { 'conf-proxy':
priority => '01',
content => template('apt/_header.erb', 'apt/proxy.erb'),
}
}
$sources_list_content = $_purge['sources.list'] ? {
false => undef,
true => "# Repos managed by puppet.\n",
}
$preferences_ensure = $_purge['preferences'] ? {
false => file,
true => absent,
}
if $_update['frequency'] == 'always' {
Exec <| title=='apt_update' |> {
refreshonly => false,
}
}
apt::setting { 'conf-update-stamp':
priority => 15,
content => template('apt/_header.erb', 'apt/15update-stamp.erb'),
}
file { 'sources.list':
ensure => file,
path => $::apt::sources_list,
owner => root,
group => root,
mode => '0644',
content => $sources_list_content,
notify => Exec['apt_update'],
}
file { 'sources.list.d':
ensure => directory,
path => $::apt::sources_list_d,
owner => root,
group => root,
mode => '0644',
purge => $_purge['sources.list.d'],
recurse => $_purge['sources.list.d'],
notify => Exec['apt_update'],
}
file { 'preferences':
ensure => $preferences_ensure,
path => $::apt::preferences,
owner => root,
group => root,
mode => '0644',
notify => Exec['apt_update'],
}
file { 'preferences.d':
ensure => directory,
path => $::apt::preferences_d,
owner => root,
group => root,
mode => '0644',
purge => $_purge['preferences.d'],
recurse => $_purge['preferences.d'],
notify => Exec['apt_update'],
}
contain 'apt::update'
# manage sources if present
if $sources {
create_resources('apt::source', $sources)
}
# manage keys if present
if $keys {
create_resources('apt::key', $keys)
}
# manage ppas if present
if $ppas {
create_resources('apt::ppa', $ppas)
}
# manage settings if present
if $settings {
create_resources('apt::setting', $settings)
}
}