From 76d0222a83d7986e8fa6f693e87218cd0931f835 Mon Sep 17 00:00:00 2001 From: John Byrne <6145795+johnbyrneio@users.noreply.github.com> Date: Mon, 12 Aug 2024 01:34:32 -0400 Subject: [PATCH] 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 --- .../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: