From a9b1af8bdd7890f194d576223955d305988161eb Mon Sep 17 00:00:00 2001 From: Adam Harwell Date: Wed, 18 Jul 2018 20:34:54 -0700 Subject: [PATCH] Yum: Add support for --downloadonly (#41506) --- lib/ansible/modules/packaging/os/yum.py | 24 ++++++++++++++++++-- test/integration/targets/yum/tasks/yum.yml | 26 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 0ebbfd490c..cced4f00e1 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -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', ''), diff --git a/test/integration/targets/yum/tasks/yum.yml b/test/integration/targets/yum/tasks/yum.yml index e01163e4bc..5c3a8ce0ba 100644 --- a/test/integration/targets/yum/tasks/yum.yml +++ b/test/integration/targets/yum/tasks/yum.yml @@ -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"