Add a 'releasever' parameter for dnf. Fixes #33314. (#37493)

* Add a 'releasever' parameter for dnf. #33314

* Set a default value for releasever

* Fix a variable name typo
This commit is contained in:
Peter Janes 2018-05-24 23:22:53 -04:00 committed by ansibot
parent 1613a739ad
commit 67493ebdee
3 changed files with 73 additions and 5 deletions

View file

@ -70,6 +70,14 @@ options:
version_added: "2.3" version_added: "2.3"
default: "/" default: "/"
releasever:
description:
- Specifies an alternative release from which all packages will be
installed.
required: false
version_added: "2.6"
default: null
autoremove: autoremove:
description: description:
- If C(yes), removes all "leaf" packages from the system that were originally - If C(yes), removes all "leaf" packages from the system that were originally
@ -180,7 +188,7 @@ def _ensure_dnf(module):
"Please install `{0}` package.".format(package)) "Please install `{0}` package.".format(package))
def _configure_base(module, base, conf_file, disable_gpg_check, installroot='/'): def _configure_base(module, base, conf_file, disable_gpg_check, installroot='/', releasever=None):
"""Configure the dnf Base object.""" """Configure the dnf Base object."""
conf = base.conf conf = base.conf
@ -196,6 +204,10 @@ def _configure_base(module, base, conf_file, disable_gpg_check, installroot='/')
# Set installroot # Set installroot
conf.installroot = installroot conf.installroot = installroot
# Set releasever
if releasever is not None:
conf.substitutions['releasever'] = releasever
# Change the configuration file path if provided # Change the configuration file path if provided
if conf_file: if conf_file:
# Fail if we can't read the configuration file. # Fail if we can't read the configuration file.
@ -225,10 +237,10 @@ def _specify_repositories(base, disablerepo, enablerepo):
repo.enable() repo.enable()
def _base(module, conf_file, disable_gpg_check, disablerepo, enablerepo, installroot): def _base(module, conf_file, disable_gpg_check, disablerepo, enablerepo, installroot, releasever):
"""Return a fully configured dnf Base object.""" """Return a fully configured dnf Base object."""
base = dnf.Base() base = dnf.Base()
_configure_base(module, base, conf_file, disable_gpg_check, installroot) _configure_base(module, base, conf_file, disable_gpg_check, installroot, releasever)
_specify_repositories(base, disablerepo, enablerepo) _specify_repositories(base, disablerepo, enablerepo)
base.fill_sack(load_system_repo='auto') base.fill_sack(load_system_repo='auto')
return base return base
@ -477,6 +489,7 @@ def main():
disable_gpg_check=dict(default=False, type='bool'), disable_gpg_check=dict(default=False, type='bool'),
installroot=dict(default='/', type='path'), installroot=dict(default='/', type='path'),
autoremove=dict(type='bool'), autoremove=dict(type='bool'),
releasever=dict(default=None),
), ),
required_one_of=[['name', 'list', 'autoremove']], required_one_of=[['name', 'list', 'autoremove']],
mutually_exclusive=[['name', 'list'], ['autoremove', 'list']], mutually_exclusive=[['name', 'list'], ['autoremove', 'list']],
@ -501,7 +514,8 @@ def main():
if params['list']: if params['list']:
base = _base( base = _base(
module, params['conf_file'], params['disable_gpg_check'], module, params['conf_file'], params['disable_gpg_check'],
params['disablerepo'], params['enablerepo'], params['installroot']) params['disablerepo'], params['enablerepo'], params['installroot'],
params['releasever'])
list_items(module, base, params['list']) list_items(module, base, params['list'])
else: else:
# Note: base takes a long time to run so we want to check for failure # Note: base takes a long time to run so we want to check for failure
@ -510,7 +524,8 @@ def main():
module.fail_json(msg="This command has to be run under the root user.") module.fail_json(msg="This command has to be run under the root user.")
base = _base( base = _base(
module, params['conf_file'], params['disable_gpg_check'], module, params['conf_file'], params['disable_gpg_check'],
params['disablerepo'], params['enablerepo'], params['installroot']) params['disablerepo'], params['enablerepo'], params['installroot'],
params['releasever'])
ensure(module, base, params['state'], params['name'], params['autoremove']) ensure(module, base, params['state'], params['name'], params['autoremove'])

View file

@ -0,0 +1,48 @@
# make an installroot
- name: Create installroot
local_action:
module: command mktemp -d "{{lookup('env', 'TMPDIR') | default('/tmp', true)}}/ansible.test.XXXXXX"
register: dnfroot
- name: Make a necessary directory
file:
path: "/{{dnfroot.stdout}}/etc/dnf/vars"
state: directory
mode: 0755
- name: Populate directory
copy:
content: "{{ansible_distribution_version}}\n"
dest: "/{{dnfroot.stdout}}/etc/dnf/vars/releasever"
- name: attempt releasever to the installroot
dnf:
name: filesystem
installroot: '/{{dnfroot.stdout}}'
releasever: 22
register: dnf_result
- name: check filesystem version
shell: rpm -q filesystem --root="/{{dnfroot.stdout}}/"
failed_when: False
register: rpm_result
- debug: var=dnf_result
- debug: var=rpm_result
- name: verify installation was done
assert:
that:
- "not dnf_result.failed | default(False)"
- "dnf_result.changed"
- "rpm_result.rc == 0"
- name: verify the version
assert:
that:
- "rpm_result.stdout.find('fc22') != -1"
- name: cleanup installroot
file:
path: "/{{dnfroot.stdout}}/"
state: absent

View file

@ -33,3 +33,8 @@
when: when:
- ansible_distribution == 'Fedora' - ansible_distribution == 'Fedora'
- ansible_distribution_major_version|int >= 23 - ansible_distribution_major_version|int >= 23
- include: 'dnfreleasever.yml'
when:
- ansible_distribution == 'Fedora'
- ansible_distribution_major_version|int >= 23