From 86166ccade8332b219e4f09de34781ec424917b5 Mon Sep 17 00:00:00 2001 From: Thibaut Decombe <68703331+UnknownPlatypus@users.noreply.github.com> Date: Sat, 19 Oct 2024 12:50:46 +0200 Subject: [PATCH] Speed up brew module package install & upgrade (#9022) * Verify installation via `brew install` return code in`_install_current_package` (Skip one brew info) * Avoid computing `current_package_is_installed` twice in a row * Verify installation via `brew install` return code in `_upgrade_current_package(Skip 2 brew commands) * Add changelog fragment * Update changelogs/fragments/9022-improve-homebrew-perf.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- changelogs/fragments/9022-improve-homebrew-perf.yml | 2 ++ plugins/modules/homebrew.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/9022-improve-homebrew-perf.yml diff --git a/changelogs/fragments/9022-improve-homebrew-perf.yml b/changelogs/fragments/9022-improve-homebrew-perf.yml new file mode 100644 index 0000000000..077b5caefc --- /dev/null +++ b/changelogs/fragments/9022-improve-homebrew-perf.yml @@ -0,0 +1,2 @@ +minor_changes: + - homebrew - speed up brew install and upgrade (https://github.com/ansible-collections/community.general/pull/9022). diff --git a/plugins/modules/homebrew.py b/plugins/modules/homebrew.py index 2b60846b43..58b13f83d4 100644 --- a/plugins/modules/homebrew.py +++ b/plugins/modules/homebrew.py @@ -572,7 +572,7 @@ class Homebrew(object): cmd = [opt for opt in opts if opt] rc, out, err = self.module.run_command(cmd) - if self._current_package_is_installed(): + if rc == 0: self.changed_count += 1 self.changed_pkgs.append(self.current_package) self.changed = True @@ -600,10 +600,11 @@ class Homebrew(object): self.message = 'Invalid package: {0}.'.format(self.current_package) raise HomebrewException(self.message) - if not self._current_package_is_installed(): + current_package_is_installed = self._current_package_is_installed() + if not current_package_is_installed: command = 'install' - if self._current_package_is_installed() and not self._current_package_is_outdated(): + if current_package_is_installed and not self._current_package_is_outdated(): self.message = 'Package is already upgraded: {0}'.format( self.current_package, ) @@ -626,7 +627,7 @@ class Homebrew(object): cmd = [opt for opt in opts if opt] rc, out, err = self.module.run_command(cmd) - if self._current_package_is_installed() and not self._current_package_is_outdated(): + if rc == 0: self.changed_count += 1 self.changed_pkgs.append(self.current_package) self.changed = True