From b14c45a16c1f8393142a2fae297d91782e6c2182 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Mon, 22 Oct 2018 21:11:45 -0500 Subject: [PATCH] Handle dnf immutable mutable datatypes (#47434) * Handle dnf immutable mutable datatypes In DNF < 3.0 are lists, and modifying them works In DNF >= 3.0 < 3.6 are lists, but modifying them doesn't work In DNF >= 3.6 have been turned into tuples, to communicate that modifying them doesn't work Further explanation of this is available via Adam Williamson from the Fedora QA Team. https://www.happyassassin.net/2018/06/27/adams-debugging-adventures-the-immutable-mutable-object/ Signed-off-by: Adam Miller (cherry picked from commit 70025e7b5632b872d03dca22318b30b79444f3f5) * add backport changelog Signed-off-by: Adam Miller --- .../fragments/dnf-immutable-mutable.yaml | 3 +++ lib/ansible/modules/packaging/os/dnf.py | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/dnf-immutable-mutable.yaml diff --git a/changelogs/fragments/dnf-immutable-mutable.yaml b/changelogs/fragments/dnf-immutable-mutable.yaml new file mode 100644 index 00000000000..2977fd03106 --- /dev/null +++ b/changelogs/fragments/dnf-immutable-mutable.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - "dnf - properly handle modifying the enable/disable excludes data field" diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index d834ecc215d..4e2b906f0e0 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -489,13 +489,26 @@ class DnfModule(YumDnf): # Set installroot conf.installroot = installroot + # Handle different DNF versions immutable mutable datatypes and + # dnf v1/v2/v3 + # + # In DNF < 3.0 are lists, and modifying them works + # In DNF >= 3.0 < 3.6 are lists, but modifying them doesn't work + # In DNF >= 3.6 have been turned into tuples, to communicate that modifying them doesn't work + # + # https://www.happyassassin.net/2018/06/27/adams-debugging-adventures-the-immutable-mutable-object/ + # # Set excludes if self.exclude: - conf.exclude(self.exclude) - + _excludes = list(conf.exclude) + _excludes.extend(self.exclude) + conf.exclude = _excludes # Set disable_excludes if self.disable_excludes: - conf.disable_excludes.append(self.disable_excludes) + _disable_excludes = list(conf.disable_excludes) + if self.disable_excludes not in _disable_excludes: + _disable_excludes.append(self.disable_excludes) + conf.disable_excludes = _disable_excludes # Set releasever if self.releasever is not None: