yum: do not hide yum's errors (#27696)

pull/20893/head
Martin Krizek 7 years ago committed by Sam Doran
parent 7974ad34f1
commit 1c4e491eac

@ -755,7 +755,6 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
if module.check_mode:
module.exit_json(changed=True, results=res['results'], changes=dict(installed=pkgs))
changed = True
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
rc, out, err = module.run_command(cmd, environ_update=lang_env)
@ -765,27 +764,25 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
# Fail on invalid urls:
if '://' in spec and ('No package %s available.' % spec in out or 'Cannot open: %s. Skipping.' % spec in err):
module.fail_json(msg='Package at %s could not be installed' % spec, rc=1, changed=False)
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,
# we get rc = 0 and 'Nothing to do' in out, not in err.
rc = 0
err = ''
out = '%s: Nothing to do' % spec
changed = False
res['rc'] = rc
res['results'].append(out)
res['msg'] += err
res['changed'] = True
# special case for groups
if spec.startswith('@'):
if ('Nothing to do' in out and rc == 0) or ('does not have any packages to install' in err):
res['changed'] = False
if rc != 0:
res['changed'] = False
module.fail_json(**res)
# FIXME - if we did an install - go and check the rpmdb to see if it actually installed
# look for each pkg in rpmdb
# look for each pkg via obsoletes
# Record change
res['changed'] = changed
return res

@ -1,21 +1,4 @@
# UNINSTALL 'yum-utils'
# The `yum` module has the smarts to auto-install `yum-utils`. To test, we
# will first uninstall `yum-utils`.
- name: check yum-utils with rpm
shell: rpm -q yum-utils
register: rpm_result
ignore_errors: true
# Don't uninstall yum-utils with the `yum` module, it would be bad. The `yum`
# module does some `repoquery` magic after removing a package. It fails when you
# remove `yum-utils.
- name: uninstall yum-utils with shell
shell: yum -y remove yum-utils
when: rpm_result|success
# UNINSTALL
# With 'yum-utils' uninstalled, the first call to 'yum' should install
# yum-utils.
- name: uninstall sos
yum: name=sos state=removed
register: yum_result
@ -232,3 +215,103 @@
installroot: '/'
state: removed
register: yum_result
- name: install group
yum:
name: "@Development Tools"
state: present
register: yum_result
- name: verify installation of the group
assert:
that:
- "yum_result.rc == 0"
- "yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: install the group again
yum:
name: "@Development Tools"
state: present
register: yum_result
- name: verify nothing changed
assert:
that:
- "yum_result.rc == 0"
- "not yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: try to install non existing group
yum:
name: "@non-existing-group"
state: present
register: yum_result
ignore_errors: True
- name: verify installation of the non existing group failed
assert:
that:
- "yum_result.rc == 1"
- "not yum_result.changed"
- "yum_result|failed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: try to install non existing file
yum:
name: /tmp/non-existing-1.0.0.fc26.noarch.rpm
state: present
register: yum_result
ignore_errors: yes
- name: verify installation failed
assert:
that:
- "yum_result|failed"
- "not yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- name: try to install from non existing url
yum:
name: http://non-existing.com/non-existing-1.0.0.fc26.noarch.rpm
state: present
register: yum_result
ignore_errors: yes
- name: verify installation failed
assert:
that:
- "yum_result|failed"
- "not yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"

Loading…
Cancel
Save