From 13631ececa4454397821d3805f4079d8cc157f33 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 9 Oct 2017 12:01:34 +0200 Subject: [PATCH] yum: check if env groups are installed (#31182) --- lib/ansible/modules/packaging/os/yum.py | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 786a248f2ae..db034065375 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -322,14 +322,28 @@ def po_to_envra(po): return '%s:%s-%s-%s.%s' % (po.epoch, po.name, po.version, po.release, po.arch) -def is_group_installed(name): +def is_group_env_installed(name): + name_lower = name.lower() + my = yum_base() - groups_list = my.doGroupLists() - for group in groups_list[0]: # list of the installed groups on the first index - name_lower = name.lower() + if yum.__version__ >= '3.4': + groups_list = my.doGroupLists(return_evgrps=True) + else: + groups_list = my.doGroupLists() + + # list of the installed groups on the first index + groups = groups_list[0] + for group in groups: if name_lower.endswith(group.name.lower()) or name_lower.endswith(group.groupid.lower()): return True + if yum.__version__ >= '3.4': + # list of the installed env_groups on the third index + envs = groups_list[2] + for env in envs: + if name_lower.endswith(env.name.lower()) or name_lower.endswith(env.environmentid.lower()): + return True + return False @@ -740,7 +754,7 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i # groups elif spec.startswith('@'): - if is_group_installed(spec): + if is_group_env_installed(spec): continue pkg = spec @@ -846,7 +860,7 @@ def remove(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, in for pkg in items: if pkg.startswith('@'): - installed = is_group_installed(pkg) + installed = is_group_env_installed(pkg) else: installed = is_installed(module, repoq, pkg, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot) @@ -879,7 +893,7 @@ def remove(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, in # at this point we check to see if the pkg is no longer present for pkg in pkgs: if pkg.startswith('@'): - installed = is_group_installed(pkg) + installed = is_group_env_installed(pkg) else: installed = is_installed(module, repoq, pkg, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot)