diff --git a/packaging/os/yum.py b/packaging/os/yum.py index 00f77d68dfc..9490a15b15d 100644 --- a/packaging/os/yum.py +++ b/packaging/os/yum.py @@ -485,6 +485,7 @@ def list_stuff(module, conf_file, stuff): def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): + pkgs = [] res = {} res['results'] = [] res['msg'] = '' @@ -540,9 +541,9 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): # short circuit all the bs - and search for it as a pkg in is_installed # if you find it then we're done if not set(['*','?']).intersection(set(spec)): - pkgs = is_installed(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos, is_pkg=True) - if pkgs: - res['results'].append('%s providing %s is already installed' % (pkgs[0], spec)) + installed_pkgs = is_installed(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos, is_pkg=True) + if installed_pkgs: + res['results'].append('%s providing %s is already installed' % (installed_pkgs[0], spec)) continue # look up what pkgs provide this @@ -586,7 +587,10 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): # the error we're catching here pkg = spec - cmd = yum_basecmd + ['install', pkg] + pkgs.append(pkg) + + if pkgs: + cmd = yum_basecmd + ['install'] + pkgs if module.check_mode: # Remove rpms downloaded for EL5 via url @@ -600,11 +604,13 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): rc, out, err = module.run_command(cmd) - # Fail on invalid urls: - if (rc == 1 and '://' in spec and ('No package %s available.' % spec in out or 'Cannot open: %s. Skipping.' % spec in err)): - err = 'Package at %s could not be installed' % spec - module.fail_json(changed=False,msg=err,rc=1) - elif (rc != 0 and 'Nothing to do' in err) or 'Nothing to do' in out: + if (rc == 1): + for spec in items: + # Fail on invalid urls: + if ('://' in spec and ('No package %s available.' % spec in out or 'Cannot open: %s. Skipping.' % spec in err)): + err = 'Package at %s could not be installed' % spec + module.fail_json(changed=False,msg=err,rc=1) + if (rc != 0 and 'Nothing to do' in err) or 'Nothing to do' in out: # avoid failing in the 'Nothing To Do' case # this may happen with an URL spec. # for an already installed group, @@ -614,16 +620,16 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): out = '%s: Nothing to do' % spec changed = False - res['rc'] += rc + res['rc'] = rc res['results'].append(out) res['msg'] += err # FIXME - if we did an install - go and check the rpmdb to see if it actually installed - # look for the pkg in rpmdb - # look for the pkg via obsoletes + # look for each pkg in rpmdb + # look for each pkg via obsoletes - # accumulate any changes - res['changed'] |= changed + # Record change + res['changed'] = changed # Remove rpms downloaded for EL5 via url try: @@ -636,6 +642,7 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): def remove(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): + pkgs = [] res = {} res['results'] = [] res['msg'] = '' @@ -652,17 +659,20 @@ def remove(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): res['results'].append('%s is not installed' % pkg) continue + pkgs.append(pkg) + + if pkgs: # run an actual yum transaction - cmd = yum_basecmd + ["remove", pkg] + cmd = yum_basecmd + ["remove"] + pkgs if module.check_mode: module.exit_json(changed=True) rc, out, err = module.run_command(cmd) - res['rc'] += rc + res['rc'] = rc res['results'].append(out) - res['msg'] += err + res['msg'] = err # compile the results into one batch. If anything is changed # then mark changed @@ -671,12 +681,13 @@ def remove(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): # at this point we should check to see if the pkg is no longer present - if not is_group: # we can't sensibly check for a group being uninstalled reliably - # look to see if the pkg shows up from is_installed. If it doesn't - if not is_installed(module, repoq, pkg, conf_file, en_repos=en_repos, dis_repos=dis_repos): - res['changed'] = True - else: - module.fail_json(**res) + for pkg in pkgs: + if not pkg.startswith('@'): # we can't sensibly check for a group being uninstalled reliably + # look to see if the pkg shows up from is_installed. If it doesn't + if not is_installed(module, repoq, pkg, conf_file, en_repos=en_repos, dis_repos=dis_repos): + res['changed'] = True + else: + module.fail_json(**res) if rc != 0: module.fail_json(**res)