From d3eeca8580b05450c493670ca7ae1a2c4ca6d0a7 Mon Sep 17 00:00:00 2001 From: Samuel Mutel Date: Thu, 29 Apr 2021 21:52:30 +0200 Subject: [PATCH] Add unattended_only_on_ac_power and install powermgmt-base (#76) Co-authored-by: Samuel Mutel --- README.md | 2 ++ defaults/main.yml | 5 +++++ tasks/unattended-upgrades.yml | 8 ++++++++ templates/unattended-upgrades.j2 | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 0be991b..ffb0529 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ On some hosts you may find that the unattended-upgrade's cronfile `/etc/cron.dai * Default: `[]` * `unattended_dl_limit`: Limit the download speed in kb/sec using apt bandwidth limit feature. * Default: disabled +* `unattended_only_on_ac_power`: Download and install upgrades only on AC power. It will also install the debian package `powermgmt-base`. + * Default: false ## Origins Patterns diff --git a/defaults/main.yml b/defaults/main.yml index a62ee01..ca97dc4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -135,3 +135,8 @@ unattended_dpkg_options: [] # Use apt bandwidth limit feature, this example limits the download speed to 70kb/sec #unattended_dl_limit: 70 + +# Unattended-Upgrade::OnlyOnACPower +# Download and install upgrades only on AC power +# (i.e. skip or gracefully stop updates on battery) +unattended_only_on_ac_power: false diff --git a/tasks/unattended-upgrades.yml b/tasks/unattended-upgrades.yml index 2b911fe..1cbf60e 100644 --- a/tasks/unattended-upgrades.yml +++ b/tasks/unattended-upgrades.yml @@ -6,6 +6,14 @@ include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" when: (ansible_distribution == "Debian") and (ansible_distribution_release == "wheezy") +- name: install powermgmt-base + apt: + pkg: + state: present + cache_valid_time: "{{ unattended_cache_valid_time }}" + update_cache: yes + when: unattended_only_on_ac_power + - name: install unattended-upgrades apt: pkg: unattended-upgrades diff --git a/templates/unattended-upgrades.j2 b/templates/unattended-upgrades.j2 index 9338c49..86b6374 100644 --- a/templates/unattended-upgrades.j2 +++ b/templates/unattended-upgrades.j2 @@ -121,3 +121,7 @@ Dpkg::Options { // speed to 70kb/sec Acquire::http::Dl-Limit "{{ unattended_dl_limit }}"; {% endif %} + +// Download and install upgrades only on AC power +// (i.e. skip or gracefully stop updates on battery) +Unattended-Upgrade::OnlyOnACPower "{{ unattended_only_on_ac_power }}";