From 5103c3cea0114e28e6d573722f6d2b826db1c086 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:06:35 +0200 Subject: [PATCH] [PR #8708/76d0222a backport][stable-9] homebrew_cask: fix upgrade_all changed when nothing upgraded (#8749) homebrew_cask: fix upgrade_all changed when nothing upgraded (#8708) * homebrew_cask: fix upgrade_all changed when nothing upgraded * Add changelog fragment * Update changelogs/fragments/8708-homebrew_cask-fix-upgrade-all.yml Co-authored-by: Felix Fontein * Add .strip() to upgrade output check Co-authored-by: Felix Fontein --------- Co-authored-by: John Byrne Co-authored-by: Felix Fontein (cherry picked from commit 76d0222a83d7986e8fa6f693e87218cd0931f835) Co-authored-by: John Byrne <6145795+johnbyrneio@users.noreply.github.com> --- .../fragments/8708-homebrew_cask-fix-upgrade-all.yml | 2 ++ plugins/modules/homebrew_cask.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/8708-homebrew_cask-fix-upgrade-all.yml diff --git a/changelogs/fragments/8708-homebrew_cask-fix-upgrade-all.yml b/changelogs/fragments/8708-homebrew_cask-fix-upgrade-all.yml new file mode 100644 index 0000000000..6a0cd74302 --- /dev/null +++ b/changelogs/fragments/8708-homebrew_cask-fix-upgrade-all.yml @@ -0,0 +1,2 @@ +bugfixes: + - homebrew_cask - fix ``upgrade_all`` returns ``changed`` when nothing upgraded (https://github.com/ansible-collections/community.general/issues/8707, https://github.com/ansible-collections/community.general/pull/8708). \ No newline at end of file diff --git a/plugins/modules/homebrew_cask.py b/plugins/modules/homebrew_cask.py index dc9aea5db8..9902cb1373 100644 --- a/plugins/modules/homebrew_cask.py +++ b/plugins/modules/homebrew_cask.py @@ -534,7 +534,12 @@ class HomebrewCask(object): rc, out, err = self.module.run_command(cmd) if rc == 0: - if re.search(r'==> No Casks to upgrade', out.strip(), re.IGNORECASE): + # 'brew upgrade --cask' does not output anything if no casks are upgraded + if not out.strip(): + self.message = 'Homebrew casks already upgraded.' + + # handle legacy 'brew cask upgrade' + elif re.search(r'==> No Casks to upgrade', out.strip(), re.IGNORECASE): self.message = 'Homebrew casks already upgraded.' else: