From 6033ce695bc891828887019439ecf11668f58086 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 12 Aug 2021 08:17:03 +0200 Subject: [PATCH] zypper: support transactional-updates (#3164) * zypper: support transactional-updates - Check if transactional updates are in use by checking for the existence of /var/lib/misc/transactional-update.state - Prefix zypper-commands with /sbin/transactional-update --continue --drop-if-no-change --quiet run if this is the case fixes ansible-collections/community.general#3159 * re-add get_bin_path for executables * fix typo --- .../3164-zypper-support-transactional-updates.yaml | 2 ++ plugins/modules/packaging/os/zypper.py | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 changelogs/fragments/3164-zypper-support-transactional-updates.yaml diff --git a/changelogs/fragments/3164-zypper-support-transactional-updates.yaml b/changelogs/fragments/3164-zypper-support-transactional-updates.yaml new file mode 100644 index 0000000000..d12ff9a6bf --- /dev/null +++ b/changelogs/fragments/3164-zypper-support-transactional-updates.yaml @@ -0,0 +1,2 @@ +minor_changes: + - zypper - prefix zypper commands with ``/sbin/transactional-update --continue --drop-if-no-change --quiet run`` if transactional updates are detected (https://github.com/ansible-collections/community.general/issues/3159). diff --git a/plugins/modules/packaging/os/zypper.py b/plugins/modules/packaging/os/zypper.py index 367bd8d9a0..2295b5a566 100644 --- a/plugins/modules/packaging/os/zypper.py +++ b/plugins/modules/packaging/os/zypper.py @@ -29,6 +29,7 @@ author: short_description: Manage packages on SUSE and openSUSE description: - Manage packages on SUSE and openSUSE using the zypper and rpm tools. + - Also supports transactional updates, by running zypper inside C(/sbin/transactional-update --continue --drop-if-no-change --quiet run). options: name: description: @@ -213,6 +214,7 @@ EXAMPLES = ''' ZYPP_LOCK_TIMEOUT: 20 ''' +import os.path import xml import re from xml.dom.minidom import parseString as parseXML @@ -337,6 +339,8 @@ def get_cmd(m, subcommand): is_install = subcommand in ['install', 'update', 'patch', 'dist-upgrade'] is_refresh = subcommand == 'refresh' cmd = [m.get_bin_path('zypper', required=True), '--quiet', '--non-interactive', '--xmlout'] + if transactional_updates(): + cmd = [m.get_bin_path('transactional-update', required=True), '--continue', '--drop-if-no-change', '--quiet', 'run'] + cmd if m.params['extra_args_precommand']: args_list = m.params['extra_args_precommand'].split() cmd.extend(args_list) @@ -491,6 +495,10 @@ def repo_refresh(m): return retvals + +def transactional_updates(): + return os.path.exists('/var/lib/misc/transactional-update.state') + # =========================================== # Main control flow