summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph (Jy) Yaworski <jyaworski@carotid.us>2016-04-02 00:41:54 -0400
committerJoseph (Jy) Yaworski <jyaworski@carotid.us>2016-04-02 00:41:54 -0400
commit9c9c140ce32395afcf8d9b5d8e4f92e4e3bb3007 (patch)
tree6908974fb30b0b99c8d70c1939511f489d43033e
parent1ddfcea4c298cbe6236622020ec440e5e0633341 (diff)
parent3a4abe4f98d4c24989a1def59968cb49d1d26268 (diff)
Merge pull request #52 from icann-dns/add_config_options
add options support
-rw-r--r--README.md7
-rw-r--r--manifests/init.pp13
-rw-r--r--manifests/params.pp5
-rw-r--r--spec/classes/unattended_upgrades_spec.rb115
-rw-r--r--templates/options.erb11
5 files changed, 150 insertions, 1 deletions
diff --git a/README.md b/README.md
index a2d3aef..c81b759 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,13 @@ Using unattended\_upgrades simply consists of including the module and if needed
}
```
* `verbose` (`0`): Send report mail to root.
+* `options` (`{}`): A hash of settings with these possible keys:
+ * `force_confdef` (`true`) : Use the default option for new config files if one
+ is available, don't prompt. If no default can be found, you will be prompted
+ unless one of the confold or confnew options is also given
+ * `force_confold` (`true`): Always use the old config files, don't prompt
+ * `force_connew` (`false`): Always use the new config files, don't prompt
+ * `force_conmiss` (`false`): Always install missing config files
## Limitations
diff --git a/manifests/init.pp b/manifests/init.pp
index 489db32..7b09d0a 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -18,6 +18,7 @@ class unattended_upgrades (
$upgradeable_packages = {},
$verbose = 0,
$notify_update = false,
+ $options = {},
) inherits ::unattended_upgrades::params {
if $legacy_origin == undef or $origins == undef {
@@ -45,6 +46,12 @@ class unattended_upgrades (
validate_integer($size)
validate_hash($upgradeable_packages)
$_upgradeable_packages = merge($::unattended_upgrades::default_upgradeable_packages, $upgradeable_packages)
+ validate_hash($options)
+ $_options = merge($unattended_upgrades::default_options, $options)
+ validate_bool($_options['force_confdef'])
+ validate_bool($_options['force_confold'])
+ validate_bool($_options['force_confnew'])
+ validate_bool($_options['force_confmiss'])
package { 'unattended-upgrades':
ensure => $package_ensure,
@@ -70,5 +77,11 @@ class unattended_upgrades (
require => Package['unattended-upgrades'],
notify_update => $notify_update,
}
+ apt::conf { 'options':
+ priority => 10,
+ content => template("${module_name}/options.erb"),
+ require => Package['unattended-upgrades'],
+ notify_update => $notify_update,
+ }
}
diff --git a/manifests/params.pp b/manifests/params.pp
index e9a7605..29bc891 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -10,7 +10,10 @@ class unattended_upgrades::params {
$default_backup = { 'archive_interval' => 0, 'level' => 3, }
$default_age = { 'min' => 2, 'max' => 0, }
$default_upgradeable_packages = { 'download_only' => 0, 'debdelta' => 1, }
-
+ $default_options = { 'force_confdef' => true,
+ 'force_confold' => true,
+ 'force_confnew' => false,
+ 'force_confmiss' => false, }
# prior to puppet 3.5.0, defined couldn't test if a variable was defined
# strict variables wasn't added until 3.5.0, so this should be fine.
if ! $::settings::strict_variables {
diff --git a/spec/classes/unattended_upgrades_spec.rb b/spec/classes/unattended_upgrades_spec.rb
index d951a87..7bc7365 100644
--- a/spec/classes/unattended_upgrades_spec.rb
+++ b/spec/classes/unattended_upgrades_spec.rb
@@ -3,6 +3,7 @@ require 'spec_helper'
describe 'unattended_upgrades' do
let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
+ let(:file_options) { '/etc/apt/apt.conf.d/10options' }
let(:facts) { {
osfamily: 'Debian',
lsbdistid: 'Debian',
@@ -31,6 +32,13 @@ describe 'unattended_upgrades' do
}
it {
+ should contain_apt__conf('options').with(
+ require: 'Package[unattended-upgrades]',
+ notify_update: false,
+ )
+ }
+
+ it {
should create_file(file_unattended).with(
owner: 'root',
group: 'root',
@@ -96,6 +104,23 @@ describe 'unattended_upgrades' do
ensure: 'absent',
)
}
+ it {
+ should create_file(file_options).with(
+ owner: 'root',
+ group: 'root',
+ mode: '0644',
+ ).with_content(
+ /^Dpkg::Options\s{/
+ ).with_content(
+ /^\s+\"--force-confdef\";/
+ ).with_content(
+ /^\s+\"--force-confold\";/
+ ).without_content(
+ /\"--force-confnew\";/
+ ).without_content(
+ /\"--force-confmiss\";/
+ )
+ }
end
context 'with defaults on Debian 6 Squeeze' do
@@ -295,6 +320,12 @@ describe 'unattended_upgrades' do
dl_limit: 70,
random_sleep: 300,
notify_update: true,
+ options: {
+ 'force_confdef' => false,
+ 'force_confold' => false,
+ 'force_confnew' => true,
+ 'force_confmiss' => true,
+ }
}
end
it { should contain_package('unattended-upgrades') }
@@ -312,6 +343,13 @@ describe 'unattended_upgrades' do
}
it {
+ should contain_apt__conf('options').with(
+ require: 'Package[unattended-upgrades]',
+ notify_update: true,
+ )
+ }
+
+ it {
should create_file(file_unattended).with(
owner: 'root',
group: 'root',
@@ -376,6 +414,23 @@ describe 'unattended_upgrades' do
}
it {
+ should create_file(file_options).with(
+ owner: 'root',
+ group: 'root',
+ mode: '0644',
+ ).with_content(
+ /^Dpkg::Options\s{/
+ ).without_content(
+ /"--force-confdef";/
+ ).without_content(
+ /"--force-confold";/
+ ).with_content(
+ /^\s+"--force-confnew";/
+ ).with_content(
+ /^\s+"--force-confmiss";/
+ )
+ }
+ it {
should contain_apt__conf('auto-upgrades').with(
ensure: 'absent',
)
@@ -527,5 +582,65 @@ describe 'unattended_upgrades' do
}.to raise_error(Puppet::Error, /not a boolean/)
end
end
+ context 'bad options[\'force_confdef\']' do
+ let :params do
+ {
+ options: { 'force_confdef' => 'foo' },
+ }
+ end
+ it do
+ expect {
+ subject.call
+ }.to raise_error(Puppet::Error, /not a boolean/)
+ end
+ end
+ context 'bad options[\'force_confold\']' do
+ let :params do
+ {
+ options: { 'force_confold' => 'foo' },
+ }
+ end
+ it do
+ expect {
+ subject.call
+ }.to raise_error(Puppet::Error, /not a boolean/)
+ end
+ end
+ context 'bad options[\'force_confnew\']' do
+ let :params do
+ {
+ options: { 'force_confnew' => 'foo' },
+ }
+ end
+ it do
+ expect {
+ subject.call
+ }.to raise_error(Puppet::Error, /not a boolean/)
+ end
+ end
+ context 'bad options[\'force_confmiss\']' do
+ let :params do
+ {
+ options: { 'force_confmiss' => 'foo' },
+ }
+ end
+ it do
+ expect {
+ subject.call
+ }.to raise_error(Puppet::Error, /not a boolean/)
+ end
+ end
+ context 'bad options[\'invalid_key\']' do
+ let :params do
+ {
+ options: { 'invalid_key' => true },
+ }
+ end
+ it do
+ expect {
+ subject.call
+ }.to raise_error(Puppet::Error, /invalid_key not a valid key/)
+ end
+ end
end
end
diff --git a/templates/options.erb b/templates/options.erb
new file mode 100644
index 0000000..036d31f
--- /dev/null
+++ b/templates/options.erb
@@ -0,0 +1,11 @@
+Dpkg::Options {
+<%- @_options.each_pair do |config, value|
+ if %w(force_confdef force_confold force_confnew force_confmiss).include?(config) then
+ if value then -%>
+ "--<%= config.sub('_','-') -%>";
+ <%- end
+ else
+ scope.function_fail(["#{config} not a valid key for $unattended_upgrades::options"])
+ end
+end -%>
+}