From d0fe612858aae108b5ebc1a9cb76ea6acfa9a960 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:06:29 +0200 Subject: [PATCH] [PR #8708/76d0222a backport][stable-8] homebrew_cask: fix upgrade_all changed when nothing upgraded (#8748) 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 c992693b68..0d035741c0 100644 --- a/plugins/modules/homebrew_cask.py +++ b/plugins/modules/homebrew_cask.py @@ -598,7 +598,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: