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

yum/dnf: Add download_dir param (#53171)

This commit is contained in:
Martin Krizek 2019-03-04 19:08:58 +01:00 committed by ansibot
parent 4ea51fd7ee
commit 239fb1f68d
6 changed files with 89 additions and 4 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- yum/dnf - Add download_dir param (https://github.com/ansible/ansible/issues/24004)

View file

@ -29,6 +29,7 @@ yumdnf_argument_spec = dict(
disable_plugin=dict(type='list', default=[]),
disablerepo=dict(type='list', default=[]),
download_only=dict(type='bool', default=False),
download_dir=dict(type='str', default=None),
enable_plugin=dict(type='list', default=[]),
enablerepo=dict(type='list', default=[]),
exclude=dict(type='list', default=[]),
@ -73,6 +74,7 @@ class YumDnf(with_metaclass(ABCMeta, object)):
self.disable_plugin = self.module.params['disable_plugin']
self.disablerepo = self.module.params.get('disablerepo', [])
self.download_only = self.module.params['download_only']
self.download_dir = self.module.params['download_dir']
self.enable_plugin = self.module.params['enable_plugin']
self.enablerepo = self.module.params.get('enablerepo', [])
self.exclude = self.module.params['exclude']

View file

@ -190,6 +190,12 @@ options:
type: bool
default: "yes"
version_added: "2.8"
download_dir:
description:
- Specifies an alternate directory to store packages.
- Has an effect only if I(download_only) is specified.
type: str
version_added: "2.8"
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.
- Group removal doesn't work if the group was installed with Ansible because
@ -564,6 +570,8 @@ class DnfModule(YumDnf):
if self.download_only:
conf.downloadonly = True
if self.download_dir:
conf.destdir = self.download_dir
# Default in dnf upstream is true
conf.clean_requirements_on_remove = self.autoremove
@ -1122,6 +1130,10 @@ class DnfModule(YumDnf):
self.module.exit_json(**response)
try:
if self.download_only and self.download_dir and self.base.conf.destdir:
dnf.util.ensure_dir(self.base.conf.destdir)
self.base.repos.all().pkgdir = self.base.conf.destdir
self.base.download_packages(self.base.transaction.install_set)
except dnf.exceptions.DownloadError as e:
self.module.fail_json(
@ -1171,6 +1183,14 @@ class DnfModule(YumDnf):
results=[],
)
# Check if download_dir is called correctly
if self.download_dir:
if LooseVersion(dnf.__version__) < LooseVersion('2.6.2'):
self.module.fail_json(
msg="download_dir requires dnf>=2.6.2. Current dnf version is %s" % dnf.__version__,
results=[],
)
if self.update_cache and not self.names and not self.list:
self.base = self._base(
self.conf_file, self.disable_gpg_check, self.disablerepo,

View file

@ -197,6 +197,12 @@ options:
type: bool
default: "yes"
version_added: "2.8"
download_dir:
description:
- Specifies an alternate directory to store packages.
- Has an effect only if I(download_only) is specified.
type: str
version_added: "2.8"
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.
@ -1385,6 +1391,9 @@ class YumModule(YumDnf):
if self.download_only:
self.yum_basecmd.extend(['--downloadonly'])
if self.download_dir:
self.yum_basecmd.extend(['--downloaddir=%s' % self.download_dir])
if self.installroot != '/':
# do not setup installroot by default, because of error
# CRITICAL:yum.cli:Config Error: Error accessing file for config file:////etc/yum.conf

View file

@ -233,13 +233,12 @@
dnf: name=sos installroot='/'
register: dnf_result
# Test download_only
- name: uninstall sos for downloadonly test
dnf:
name: sos
state: absent
- name: install sos
- name: Test download_only
dnf:
name: sos
state: latest
@ -264,6 +263,33 @@
- "dnf_result is success"
- "not dnf_result is changed"
- name: uninstall sos for downloadonly/downloaddir test
dnf:
name: sos
state: absent
- name: Test download_only/download_dir
dnf:
name: sos
state: latest
download_only: true
download_dir: "/var/tmp/packages"
register: dnf_result
- name: verify dnf output
assert:
that:
- "dnf_result is success"
- "dnf_result is changed"
- command: "ls /var/tmp/packages"
register: ls_out
- name: Verify specified download_dir was used
assert:
that:
- "'sos' in ls_out.stdout"
# GROUP INSTALL
- name: install Custom Group group
dnf:

View file

@ -303,8 +303,7 @@
state: removed
register: yum_result
# Test download_only
- name: install sos
- name: Test download_only
yum:
name: sos
state: latest
@ -329,6 +328,33 @@
- "yum_result is success"
- "not yum_result is changed"
- name: uninstall sos for downloadonly/downloaddir test
yum:
name: sos
state: absent
- name: Test download_only/download_dir
yum:
name: sos
state: latest
download_only: true
download_dir: "/var/tmp/packages"
register: yum_result
- name: verify yum output
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- command: "ls /var/tmp/packages"
register: ls_out
- name: Verify specified download_dir was used
assert:
that:
- "'sos' in ls_out.stdout"
- name: install group
yum:
name: "@Development Tools"