1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Yum: Add support for --downloadonly (#41506)

This commit is contained in:
Adam Harwell 2018-07-18 20:34:54 -07:00 committed by ansibot
parent 2c4ba7a9e9
commit a9b1af8bdd
2 changed files with 48 additions and 2 deletions

View file

@ -155,6 +155,13 @@ options:
required: false required: false
choices: [ all, main, repoid ] choices: [ all, main, repoid ]
version_added: "2.7" version_added: "2.7"
download_only:
description:
- Only download the packages, do not install them.
required: false
default: "no"
type: bool
version_added: "2.7"
notes: notes:
- When used with a `loop:` each package will be processed individually, - When used with a `loop:` each package will be processed individually,
it is much more efficient to pass the list directly to the `name` option. it is much more efficient to pass the list directly to the `name` option.
@ -269,6 +276,13 @@ EXAMPLES = '''
- postgresql - postgresql
- postgresql-server - postgresql-server
state: present state: present
- name: Download the nginx package but do not install it
yum:
name:
- nginx
state: latest
download_only: true
''' '''
import os import os
@ -1306,7 +1320,7 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, en
def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo, def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
disable_gpg_check, exclude, repoq, skip_broken, update_only, security, disable_gpg_check, exclude, repoq, skip_broken, update_only, security,
bugfix, installroot='/', allow_downgrade=False, disable_plugin=None, bugfix, installroot='/', allow_downgrade=False, disable_plugin=None,
enable_plugin=None, disable_excludes=None): enable_plugin=None, disable_excludes=None, download_only=False):
# fedora will redirect yum to dnf, which has incompatibilities # fedora will redirect yum to dnf, which has incompatibilities
# with how this module expects yum to operate. If yum-deprecated # with how this module expects yum to operate. If yum-deprecated
@ -1352,6 +1366,9 @@ def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
if disable_excludes: if disable_excludes:
yum_basecmd.extend(['--disableexcludes=%s' % disable_excludes]) yum_basecmd.extend(['--disableexcludes=%s' % disable_excludes])
if download_only:
yum_basecmd.extend(['--downloadonly'])
if installroot != '/': if installroot != '/':
# do not setup installroot by default, because of error # do not setup installroot by default, because of error
# CRITICAL:yum.cli:Config Error: Error accessing file for config file:////etc/yum.conf # CRITICAL:yum.cli:Config Error: Error accessing file for config file:////etc/yum.conf
@ -1467,6 +1484,7 @@ def main():
enable_plugin=dict(type='list', default=[]), enable_plugin=dict(type='list', default=[]),
disable_plugin=dict(type='list', default=[]), disable_plugin=dict(type='list', default=[]),
disable_excludes=dict(type='str', default=None, choices=['all', 'main', 'repoid']), disable_excludes=dict(type='str', default=None, choices=['all', 'main', 'repoid']),
download_only=dict(type='bool', default=False),
), ),
required_one_of=[['name', 'list']], required_one_of=[['name', 'list']],
mutually_exclusive=[['name', 'list']], mutually_exclusive=[['name', 'list']],
@ -1528,10 +1546,12 @@ def main():
security = params['security'] security = params['security']
bugfix = params['bugfix'] bugfix = params['bugfix']
allow_downgrade = params['allow_downgrade'] allow_downgrade = params['allow_downgrade']
download_only = params['download_only']
results = ensure(module, state, pkg, params['conf_file'], enablerepo, results = ensure(module, state, pkg, params['conf_file'], enablerepo,
disablerepo, disable_gpg_check, exclude, repoquery, disablerepo, disable_gpg_check, exclude, repoquery,
skip_broken, update_only, security, bugfix, params['installroot'], allow_downgrade, skip_broken, update_only, security, bugfix, params['installroot'], allow_downgrade,
disable_plugin=disable_plugin, enable_plugin=enable_plugin, disable_excludes=params['disable_excludes']) disable_plugin=disable_plugin, enable_plugin=enable_plugin,
disable_excludes=params['disable_excludes'], download_only=download_only)
if repoquery: if repoquery:
results['msg'] = '%s %s' % ( results['msg'] = '%s %s' % (
results.get('msg', ''), results.get('msg', ''),

View file

@ -260,6 +260,32 @@
state: removed state: removed
register: yum_result register: yum_result
# Test download_only
- name: install sos
yum:
name: sos
state: latest
download_only: true
register: yum_result
- name: verify download of sos (part 1 -- yum "install" succeeded)
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: uninstall sos (noop)
yum:
name: sos
state: removed
register: yum_result
- name: verify download of sos (part 2 -- nothing removed during uninstall)
assert:
that:
- "yum_result is success"
- "not yum_result is changed"
- name: install group - name: install group
yum: yum:
name: "@Development Tools" name: "@Development Tools"