From 5ec381337035960232d6e531dca8442939962c8e Mon Sep 17 00:00:00 2001 From: Ryan Rotter Date: Mon, 23 Dec 2024 11:30:03 -0500 Subject: [PATCH] Add skip_updates_on_metered_connection option --- README.md | 1 + manifests/init.pp | 1 + spec/classes/unattended_upgrades_spec.rb | 3 +++ templates/unattended-upgrades.erb | 6 ++++++ 4 files changed, 11 insertions(+) diff --git a/README.md b/README.md index d9cc032..04f9aff 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ altering some of the default settings. * `syslog_enable` (`undef`): Enable logging to syslog. Default is False. * `syslog_facility` (`undef`): Specify syslog facility. Default is `daemon`. * `only_on_ac_power` (`undef`): Download and install upgrades only on AC power. Default is `true`. +* `skip_updates_on_metered_connection` (`undef`): Download and install upgrades only on non-metered connection. Default is `true`. * `allow_downgrade` (`undef`): Allow package downgrade if Pin-Priority exceeds 1000. Default is `false`. * `dpkg_options` (`[]`): Pass options to `dpkg` diff --git a/manifests/init.pp b/manifests/init.pp index 0a2fd8f..5c5a0be 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -26,6 +26,7 @@ Optional[Boolean] $syslog_enable = undef, Optional[String] $syslog_facility = undef, Optional[Boolean] $only_on_ac_power = undef, + Optional[Boolean] $skip_updates_on_metered_connection = undef, Optional[Boolean] $whitelist_strict = undef, Optional[Boolean] $allow_downgrade = undef, Array[String[1]] $dpkg_options = [], diff --git a/spec/classes/unattended_upgrades_spec.rb b/spec/classes/unattended_upgrades_spec.rb index c5ae519..886e0fe 100644 --- a/spec/classes/unattended_upgrades_spec.rb +++ b/spec/classes/unattended_upgrades_spec.rb @@ -76,6 +76,7 @@ syslog_enable: true, syslog_facility: 'daemon', only_on_ac_power: false, + skip_updates_on_metered_connection: false, whitelist_strict: true, allow_downgrade: false, dpkg_options: ['--force-confold', '--force-confdef'], @@ -146,6 +147,8 @@ %r{Unattended-Upgrade::SyslogFacility "daemon";} ).with_content( %r{Unattended-Upgrade::OnlyOnACPower "false";} + ).with_content( + %r{Unattended-Upgrade::Skip-Updates-On-Metered-Connections "false";} ).with_content( %r{Unattended-Upgrade::Allow-downgrade "false";} ).with_content( diff --git a/templates/unattended-upgrades.erb b/templates/unattended-upgrades.erb index 80d6b03..7228436 100644 --- a/templates/unattended-upgrades.erb +++ b/templates/unattended-upgrades.erb @@ -135,6 +135,12 @@ Unattended-Upgrade::SyslogFacility "<%= @syslog_facility %>"; Unattended-Upgrade::OnlyOnACPower "<%= @only_on_ac_power %>"; <%- end -%> +<%- unless @skip_updates_on_metered_connection.nil? -%> +// Download and install upgrades only on non-metered connection +// (i.e. skip or gracefully stop updates on a metered connection) +Unattended-Upgrade::Skip-Updates-On-Metered-Connections "<%= @skip_updates_on_metered_connection %>"; +<%- end -%> + <%- unless @allow_downgrade.nil? -%> // Allow package downgrade if Pin-Priority exceeds 1000 Unattended-Upgrade::Allow-downgrade "<%= @allow_downgrade %>";