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
choices: [ all, main, repoid ]
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:
- 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.
@ -269,6 +276,13 @@ EXAMPLES = '''
- postgresql
- postgresql-server
state: present
- name: Download the nginx package but do not install it
yum:
name:
- nginx
state: latest
download_only: true
'''
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,
disable_gpg_check, exclude, repoq, skip_broken, update_only, security,
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
# 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:
yum_basecmd.extend(['--disableexcludes=%s' % disable_excludes])
if download_only:
yum_basecmd.extend(['--downloadonly'])
if installroot != '/':
# do not setup installroot by default, because of error
# 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=[]),
disable_plugin=dict(type='list', default=[]),
disable_excludes=dict(type='str', default=None, choices=['all', 'main', 'repoid']),
download_only=dict(type='bool', default=False),
),
required_one_of=[['name', 'list']],
mutually_exclusive=[['name', 'list']],
@ -1528,10 +1546,12 @@ def main():
security = params['security']
bugfix = params['bugfix']
allow_downgrade = params['allow_downgrade']
download_only = params['download_only']
results = ensure(module, state, pkg, params['conf_file'], enablerepo,
disablerepo, disable_gpg_check, exclude, repoquery,
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:
results['msg'] = '%s %s' % (
results.get('msg', ''),

View file

@ -260,6 +260,32 @@
state: removed
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
yum:
name: "@Development Tools"