From 646ca748100ab85f3e9292e0da77023352269672 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 1 Feb 2021 11:32:50 +0100 Subject: [PATCH] homebrew_tap: Add support for brew search path (#1708) (#1709) * homebrew_tap: Add support for brew search path User can specify search path for brew executable. Fixes: #1702 Signed-off-by: Abhijeet Kasurde * Change version Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit d0f097c87191232106ce588f0ef73c5076c31095) Co-authored-by: Abhijeet Kasurde --- changelogs/fragments/1702_homebrew_tap.yml | 2 ++ plugins/modules/packaging/os/homebrew_tap.py | 21 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/1702_homebrew_tap.yml diff --git a/changelogs/fragments/1702_homebrew_tap.yml b/changelogs/fragments/1702_homebrew_tap.yml new file mode 100644 index 0000000000..7eabc45a9b --- /dev/null +++ b/changelogs/fragments/1702_homebrew_tap.yml @@ -0,0 +1,2 @@ +minor_changes: +- homebrew_tap - add support to specify search path for ``brew`` executable (https://github.com/ansible-collections/community.general/issues/1702). diff --git a/plugins/modules/packaging/os/homebrew_tap.py b/plugins/modules/packaging/os/homebrew_tap.py index 99cff69b00..6b30fdb68f 100644 --- a/plugins/modules/packaging/os/homebrew_tap.py +++ b/plugins/modules/packaging/os/homebrew_tap.py @@ -45,6 +45,12 @@ options: required: false default: 'present' type: str + path: + description: + - "A ':' separated list of paths to search for C(brew) executable." + default: '/usr/local/bin:/opt/homebrew/bin' + type: path + version_added: '2.1.0' requirements: [ homebrew ] ''' @@ -127,7 +133,7 @@ def add_tap(module, brew_path, tap, url=None): def add_taps(module, brew_path, taps): '''Adds one or more taps.''' - failed, unchanged, added, msg = False, 0, 0, '' + failed, changed, unchanged, added, msg = False, False, 0, 0, '' for tap in taps: (failed, changed, msg) = add_tap(module, brew_path, tap) @@ -182,7 +188,7 @@ def remove_tap(module, brew_path, tap): def remove_taps(module, brew_path, taps): '''Removes one or more taps.''' - failed, unchanged, removed, msg = False, 0, 0, '' + failed, changed, unchanged, removed, msg = False, False, 0, 0, '' for tap in taps: (failed, changed, msg) = remove_tap(module, brew_path, tap) @@ -211,14 +217,23 @@ def main(): name=dict(aliases=['tap'], type='list', required=True, elements='str'), url=dict(default=None, required=False), state=dict(default='present', choices=['present', 'absent']), + path=dict( + default="/usr/local/bin:/opt/homebrew/bin", + required=False, + type='path', + ), ), supports_check_mode=True, ) + path = module.params['path'] + if path: + path = path.split(':') + brew_path = module.get_bin_path( 'brew', required=True, - opt_dirs=['/usr/local/bin', '/opt/homebrew/bin'] + opt_dirs=path, ) taps = module.params['name']