2015-02-20 13:00:17 +01:00
|
|
|
define apt::setting (
|
2015-02-26 21:44:06 +01:00
|
|
|
$priority = 50,
|
|
|
|
$ensure = file,
|
|
|
|
$source = undef,
|
|
|
|
$content = undef,
|
|
|
|
$notify_update = true,
|
2015-02-20 13:00:17 +01:00
|
|
|
) {
|
|
|
|
|
2015-06-04 02:19:16 +02:00
|
|
|
include 'apt::params'
|
2015-02-20 13:00:17 +01:00
|
|
|
if $content and $source {
|
|
|
|
fail('apt::setting cannot have both content and source')
|
|
|
|
}
|
|
|
|
|
|
|
|
if !$content and !$source {
|
|
|
|
fail('apt::setting needs either of content or source')
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_re($ensure, ['file', 'present', 'absent'])
|
2015-02-26 21:44:06 +01:00
|
|
|
validate_bool($notify_update)
|
2015-02-26 19:12:53 +01:00
|
|
|
|
|
|
|
$title_array = split($title, '-')
|
|
|
|
$setting_type = $title_array[0]
|
|
|
|
$base_name = join(delete_at($title_array, 0), '-')
|
|
|
|
|
|
|
|
validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
|
2015-02-20 13:00:17 +01:00
|
|
|
|
|
|
|
unless is_integer($priority) {
|
2015-02-24 22:53:25 +01:00
|
|
|
# need this to allow zero-padded priority.
|
2015-02-26 19:12:53 +01:00
|
|
|
validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
|
2015-02-20 13:00:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if $source {
|
|
|
|
validate_string($source)
|
|
|
|
}
|
|
|
|
|
|
|
|
if $content {
|
|
|
|
validate_string($content)
|
|
|
|
}
|
|
|
|
|
2015-08-24 18:53:02 +02:00
|
|
|
if ($setting_type == 'list') or ($setting_type == 'pref') {
|
2015-02-20 13:00:17 +01:00
|
|
|
$_priority = ''
|
|
|
|
} else {
|
|
|
|
$_priority = $priority
|
|
|
|
}
|
|
|
|
|
2015-06-04 02:19:16 +02:00
|
|
|
$_path = $::apt::params::config_files[$setting_type]['path']
|
|
|
|
$_ext = $::apt::params::config_files[$setting_type]['ext']
|
2015-02-20 13:00:17 +01:00
|
|
|
|
2015-02-26 21:44:06 +01:00
|
|
|
if $notify_update {
|
2015-07-18 01:19:33 +02:00
|
|
|
$_notify = Class['apt::update']
|
2015-02-26 21:44:06 +01:00
|
|
|
} else {
|
|
|
|
$_notify = undef
|
|
|
|
}
|
|
|
|
|
2015-02-25 00:51:41 +01:00
|
|
|
file { "${_path}/${_priority}${base_name}${_ext}":
|
2015-02-20 13:00:17 +01:00
|
|
|
ensure => $ensure,
|
2015-03-02 20:37:01 +01:00
|
|
|
owner => 'root',
|
|
|
|
group => 'root',
|
|
|
|
mode => '0644',
|
2015-02-20 13:00:17 +01:00
|
|
|
content => $content,
|
|
|
|
source => $source,
|
2015-02-26 21:44:06 +01:00
|
|
|
notify => $_notify,
|
|
|
|
}
|
2015-02-20 13:00:17 +01:00
|
|
|
}
|