Skip to content

Commit

Permalink
Yum: Add support for --downloadonly (ansible#41506)
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-you authored and ansibot committed Jul 19, 2018
1 parent 2c4ba7a commit a9b1af8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/ansible/modules/packaging/os/yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@
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.
Expand Down Expand Up @@ -269,6 +276,13 @@
- 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']],
Expand Down Expand Up @@ -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', ''),
Expand Down
26 changes: 26 additions & 0 deletions test/integration/targets/yum/tasks/yum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a9b1af8

Please sign in to comment.