From 282deb3291c38acb69160a1cc12c71723dd15be5 Mon Sep 17 00:00:00 2001 From: Will Keeling Date: Thu, 11 Feb 2016 20:44:30 +0000 Subject: [PATCH] Better handling of package groups in pacman module --- packaging/os/pacman.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packaging/os/pacman.py b/packaging/os/pacman.py index 81b9c907772..2e444c1448c 100644 --- a/packaging/os/pacman.py +++ b/packaging/os/pacman.py @@ -267,6 +267,25 @@ def check_packages(module, pacman_path, packages, state): module.exit_json(changed=False, msg="package(s) already %s" % state) +def expand_package_groups(module, pacman_path, pkgs): + expanded = [] + + for pkg in pkgs: + cmd = "%s -Sgq %s" % (pacman_path, pkg) + rc, stdout, stderr = module.run_command(cmd, check_rc=False) + + if rc == 0: + # A group was found matching the name, so expand it + for name in stdout.split('\n'): + name = name.strip() + if name: + expanded.append(name) + else: + expanded.append(pkg) + + return expanded + + def main(): module = AnsibleModule( argument_spec = dict( @@ -305,7 +324,7 @@ def main(): upgrade(module, pacman_path) if p['name']: - pkgs = p['name'] + pkgs = expand_package_groups(module, pacman_path, p['name']) pkg_files = [] for i, pkg in enumerate(pkgs):