Adds the exclude= option to the yum module. Works the same way --exclude does when yum install or yum update

This commit is contained in:
Jonathan Mainguy 2014-11-11 19:49:56 -05:00 committed by Matt Clay
parent 6a39dc891a
commit f662a48de7

View file

@ -48,6 +48,12 @@ options:
required: true required: true
default: null default: null
aliases: [] aliases: []
exclude:
description:
- "Package name(s) to exlude when state=present, or latest
required: false
version_added: "2.0"
default: null
list: list:
description: description:
- Various (non-idempotent) commands for usage with C(/usr/bin/ansible) and I(not) playbooks. See examples. - Various (non-idempotent) commands for usage with C(/usr/bin/ansible) and I(not) playbooks. See examples.
@ -716,7 +722,7 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
module.exit_json(**res) module.exit_json(**res)
def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo, def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
disable_gpg_check): disable_gpg_check, exclude):
# need debug level 2 to get 'Nothing to do' for groupinstall. # need debug level 2 to get 'Nothing to do' for groupinstall.
yum_basecmd = [yumbin, '-d', '2', '-y'] yum_basecmd = [yumbin, '-d', '2', '-y']
@ -742,6 +748,9 @@ def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
r_cmd = ['--enablerepo=%s' % enablerepo] r_cmd = ['--enablerepo=%s' % enablerepo]
yum_basecmd.extend(r_cmd) yum_basecmd.extend(r_cmd)
if exclude:
e_cmd = ['--exclude=%s' % exclude]
yum_basecmd.extend(e_cmd)
if state in ['installed', 'present', 'latest']: if state in ['installed', 'present', 'latest']:
@ -796,6 +805,7 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec = dict(
name=dict(aliases=['pkg'], type="list"), name=dict(aliases=['pkg'], type="list"),
exclude=dict(required=False, default=None),
# removed==absent, installed==present, these are accepted as aliases # removed==absent, installed==present, these are accepted as aliases
state=dict(default='installed', choices=['absent','present','installed','removed','latest']), state=dict(default='installed', choices=['absent','present','installed','removed','latest']),
enablerepo=dict(), enablerepo=dict(),
@ -825,12 +835,13 @@ def main():
else: else:
pkg = [ p.strip() for p in params['name']] pkg = [ p.strip() for p in params['name']]
exclude = params['exclude']
state = params['state'] state = params['state']
enablerepo = params.get('enablerepo', '') enablerepo = params.get('enablerepo', '')
disablerepo = params.get('disablerepo', '') disablerepo = params.get('disablerepo', '')
disable_gpg_check = params['disable_gpg_check'] disable_gpg_check = params['disable_gpg_check']
res = ensure(module, state, pkg, params['conf_file'], enablerepo, res = ensure(module, state, pkg, params['conf_file'], enablerepo,
disablerepo, disable_gpg_check) disablerepo, disable_gpg_check, exclude)
module.fail_json(msg="we should never get here unless this all failed", **res) module.fail_json(msg="we should never get here unless this all failed", **res)
# import module snippets # import module snippets