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

Added 'extra_install_args' module option to allow extra upgrade/install specific zypper arguments (#382)

* Added 'extra_install_args' option to allow extra upgrade/install

Example zypper args for this is

* --allow-vendor-change
* --replacefiles and
* --force-resolution

* Fix comment issue..

* Change extra_install_args option to a list.

Improved doc.

* Update plugins/modules/packaging/os/zypper.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/packaging/os/zypper.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Switch from using extra_install_args to individual module options.

* Fix syntax errors and limit 'allow-vendor-change' to 'dist-upgrade'

* Removed un-needed import

* Added changelog fragment

* Added tests for zypper replacefiles and allow_vendor_change options

* Removed dist-upgrade as it changes the test environment.

And it is hard to undo.

* Added proper test of replacefiles zypper option

Buiding two rpm packages containing same file path but with different content.
Making sure we fail to install them without the replacefiles options and that we succeed
using it.

* Make sure to create directory before writing files

* Fix indentation of ignore_errors

* Correct genereated rpm file name

* Improved duplicate file assertions

* Ensure no previous netcat package still exists.

* Corrected naming of example task.

* Fix variable name typo.

* Fix proper duplicate_content access

* Make sure to clean up duplicate rpms after tests.

* Removed debug

* Removed version_added of option allow_vendor_change and replacefiles

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Martin Budsjö 2020-06-05 08:01:21 +02:00 committed by GitHub
parent a0c5580fc3
commit 77c29a1542
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 127 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- zypper - Added ``allow_vendor_change`` and ``replacefiles`` zypper options (https://github.com/ansible-collections/community.general/issues/381)

View file

@ -106,6 +106,18 @@ options:
description: description:
- Add additional options to C(zypper) command. - Add additional options to C(zypper) command.
- Options should be supplied in a single line as if given in the command line. - Options should be supplied in a single line as if given in the command line.
allow_vendor_change:
type: bool
required: false
default: false
description:
- Adds C(--allow_vendor_change) option to I(zypper) dist-upgrade command.
replacefiles:
type: bool
required: false
default: false
description:
- Adds C(--replacefiles) option to I(zypper) install/update command.
notes: notes:
- When used with a `loop:` each package will be processed individually, - 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. it is much more efficient to pass the list directly to the `name` option.
@ -164,7 +176,14 @@ EXAMPLES = '''
zypper: zypper:
name: '*' name: '*'
state: dist-upgrade state: dist-upgrade
extra_args: '--no-allow-vendor-change --allow-arch-change' allow_vendor_change: true
extra_args: '--allow-arch-change'
- name: Perform a installaion of nmap with the install option replacefiles
zypper:
name: 'nmap'
state: latest
replacefiles: true
- name: Refresh repositories and update package openssl - name: Refresh repositories and update package openssl
zypper: zypper:
@ -188,7 +207,6 @@ EXAMPLES = '''
import xml import xml
import re import re
from xml.dom.minidom import parseString as parseXML from xml.dom.minidom import parseString as parseXML
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native
# import module snippets # import module snippets
@ -335,6 +353,10 @@ def get_cmd(m, subcommand):
cmd.append('--force-resolution') cmd.append('--force-resolution')
if m.params['oldpackage']: if m.params['oldpackage']:
cmd.append('--oldpackage') cmd.append('--oldpackage')
if m.params['replacefiles']:
cmd.append('--replacefiles')
if subcommand == 'dist-upgrade' and m.params['allow_vendor_change']:
cmd.append('--allow-vendor-change')
if m.params['extra_args']: if m.params['extra_args']:
args_list = m.params['extra_args'].split(' ') args_list = m.params['extra_args'].split(' ')
cmd.extend(args_list) cmd.extend(args_list)
@ -478,6 +500,8 @@ def main():
update_cache=dict(required=False, aliases=['refresh'], default='no', type='bool'), update_cache=dict(required=False, aliases=['refresh'], default='no', type='bool'),
oldpackage=dict(required=False, default='no', type='bool'), oldpackage=dict(required=False, default='no', type='bool'),
extra_args=dict(required=False, default=None), extra_args=dict(required=False, default=None),
allow_vendor_change=dict(required=False, default=False, type='bool'),
replacefiles=dict(required=False, default=False, type='bool')
), ),
supports_check_mode=True supports_check_mode=True
) )

View file

@ -419,6 +419,12 @@
- zypper_result_update_cache_check is successful - zypper_result_update_cache_check is successful
- zypper_result_update_cache_check is not changed - zypper_result_update_cache_check is not changed
- name: ensure no previous netcat package still exists
zypper:
name:
- netcat-openbsd
- gnu-netcat
state: absent
- name: install netcat-openbsd which conflicts with gnu-netcat - name: install netcat-openbsd which conflicts with gnu-netcat
zypper: zypper:
@ -442,3 +448,78 @@
name: gnu-netcat name: gnu-netcat
state: present state: present
force_resolution: True force_resolution: True
- name: duplicate rpms block
vars:
looplist:
- 1
- 2
block:
- name: Deploy spec files to build 2 packages with duplicate files.
template:
src: duplicate.spec.j2
dest: "{{ output_dir | expanduser }}/zypper2/duplicate{{ item }}.spec"
loop: "{{ looplist }}"
- name: build rpms with duplicate files
command: |
rpmbuild -bb \
--define "_topdir {{output_dir | expanduser }}/zypper2/rpm-build"
--define "_builddir %{_topdir}" \
--define "_rpmdir %{_topdir}" \
--define "_srcrpmdir %{_topdir}" \
--define "_specdir {{output_dir | expanduser}}/zypper2" \
--define "_sourcedir %{_topdir}" \
{{ output_dir | expanduser }}/zypper2/duplicate{{ item }}.spec
loop: "{{ looplist }}"
- name: install duplicate rpms
zypper:
name: >-
{{ output_dir | expanduser }}/zypper2/rpm-build/noarch/duplicate{{ item }}-1-0.noarch.rpm
disable_gpg_check: true
ignore_errors: true
register: zypper_duplicate_result
loop: "{{ looplist }}"
- name: Read in duplicate file contents
slurp:
src: /usr/lib/duplicate/duplicate.txt
register: duplicate_out
- name: Check failure when installing rpms with duplicate files without replacefiles option
assert:
that:
- zypper_duplicate_result.results[0] is successful
- zypper_duplicate_result.results[1] is failed
- '"fileconflict" in zypper_duplicate_result.results[1].stdout'
- '"/usr/lib/duplicate/duplicate.txt" in zypper_duplicate_result.results[1].stdout'
- '"duplicate1" in duplicate_out.content | b64decode'
- name: install duplicate rpms
zypper:
name: >-
{{ output_dir | expanduser }}/zypper2/rpm-build/noarch/duplicate{{ item }}-1-0.noarch.rpm
disable_gpg_check: true
replacefiles: true
ignore_errors: true
register: zypper_duplicate_result
loop: "{{ looplist }}"
- name: Read in duplicate file contents
slurp:
src: /usr/lib/duplicate/duplicate.txt
register: duplicate_out
- name: Check success installing rpms with duplicate files using replacefiles option
assert:
that:
- zypper_duplicate_result is successful
- zypper_duplicate_result is changed
- '"duplicate2" in duplicate_out.content | b64decode'
- name: Remove installed duplicate rpms
zypper:
name: "duplicate{{ item }}-1-0"
state: absent
loop: "{{ looplist }}"

View file

@ -0,0 +1,18 @@
Summary: Duplicate{{ item }} RPM. Installs one file that is a duplicate of other Duplicate# RPMs
Name: duplicate{{ item }}
Version: 1
Release: 0
License: GPLv3
Group: Applications/System
BuildArch: noarch
%description
Duplicate {{ item }} RPM. Package one file that will be a duplicate of other Duplicate RPM contents.
This is only for testing of the replacefiles zypper option.
%install
mkdir -p "%{buildroot}/usr/lib/duplicate"
echo "%{name}" > "%{buildroot}/usr/lib/duplicate/duplicate.txt"
%files
/usr/lib/duplicate/duplicate.txt