summaryrefslogtreecommitdiffstats
path: root/ansible_collections/community/general/plugins/modules/homebrew.py
diff options
context:
space:
mode:
Diffstat (limited to 'ansible_collections/community/general/plugins/modules/homebrew.py')
-rw-r--r--ansible_collections/community/general/plugins/modules/homebrew.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/ansible_collections/community/general/plugins/modules/homebrew.py b/ansible_collections/community/general/plugins/modules/homebrew.py
index 7592f95a4..5d471797a 100644
--- a/ansible_collections/community/general/plugins/modules/homebrew.py
+++ b/ansible_collections/community/general/plugins/modules/homebrew.py
@@ -42,9 +42,9 @@ options:
elements: str
path:
description:
- - "A C(:) separated list of paths to search for C(brew) executable.
- Since a package (I(formula) in homebrew parlance) location is prefixed relative to the actual path of I(brew) command,
- providing an alternative I(brew) path enables managing different set of packages in an alternative location in the system."
+ - "A V(:) separated list of paths to search for C(brew) executable.
+ Since a package (I(formula) in homebrew parlance) location is prefixed relative to the actual path of C(brew) command,
+ providing an alternative C(brew) path enables managing different set of packages in an alternative location in the system."
default: '/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin'
type: path
state:
@@ -78,7 +78,7 @@ options:
version_added: '0.2.0'
notes:
- When used with a C(loop:) each package will be processed individually,
- it is much more efficient to pass the list directly to the I(name) option.
+ it is much more efficient to pass the list directly to the O(name) option.
'''
EXAMPLES = '''
@@ -87,7 +87,7 @@ EXAMPLES = '''
name: foo
state: present
-# Install formula foo with 'brew' in alternate path C(/my/other/location/bin)
+# Install formula foo with 'brew' in alternate path (/my/other/location/bin)
- community.general.homebrew:
name: foo
path: /my/other/location/bin
@@ -165,6 +165,7 @@ changed_pkgs:
version_added: '0.2.0'
'''
+import json
import os.path
import re
@@ -184,6 +185,10 @@ def _create_regex_group_complement(s):
chars = filter(None, (line.split('#')[0].strip() for line in lines))
group = r'[^' + r''.join(chars) + r']'
return re.compile(group)
+
+
+def _check_package_in_json(json_output, package_type):
+ return bool(json_output.get(package_type, []) and json_output[package_type][0].get("installed"))
# /utils ------------------------------------------------------------------ }}}
@@ -479,17 +484,17 @@ class Homebrew(object):
cmd = [
"{brew_path}".format(brew_path=self.brew_path),
"info",
+ "--json=v2",
self.current_package,
]
rc, out, err = self.module.run_command(cmd)
- for line in out.split('\n'):
- if (
- re.search(r'Built from source', line)
- or re.search(r'Poured from bottle', line)
- ):
- return True
-
- return False
+ if err:
+ self.failed = True
+ self.message = err.strip()
+ raise HomebrewException(self.message)
+ data = json.loads(out)
+
+ return _check_package_in_json(data, "formulae") or _check_package_in_json(data, "casks")
def _current_package_is_outdated(self):
if not self.valid_package(self.current_package):