mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-07 11:10:31 -07:00
zypper: add simple_errors option - fixes #8416 (#9270)
* zypper: add simple_errors option -fixes #8416
* Fix style issues
* Apply suggestions from code review
Co-authored-by: Felix Fontein <felix@fontein.de>
* Fix indentation
* Add changelog fragment
* Apply suggestions from code review
Co-authored-by: Felix Fontein <felix@fontein.de>
* Updated as per code review recommendations
* Fix whitespace
* Add quiet option, fix logic, update changelog
* Fix trailing whitespace
* Update plugins/modules/zypper.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Add suggested improvements
---------
Co-authored-by: Eric Hoogeveen <eric.hoogeveen@ssc-spc.gc.ca>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 825e0ee377
)
Co-authored-by: Eric <8869330+erichoog@users.noreply.github.com>
This commit is contained in:
parent
7e6514b4d4
commit
74bd7f1471
2 changed files with 50 additions and 1 deletions
3
changelogs/fragments/9270-zypper-add-simple_errors.yaml
Normal file
3
changelogs/fragments/9270-zypper-add-simple_errors.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
minor_changes:
|
||||||
|
- zypper - add ``simple_errors`` option (https://github.com/ansible-collections/community.general/pull/9270).
|
||||||
|
- zypper - add ``quiet`` option (https://github.com/ansible-collections/community.general/pull/9270).
|
|
@ -142,6 +142,20 @@ options:
|
||||||
description:
|
description:
|
||||||
- Adds C(--clean-deps) option to I(zypper) remove command.
|
- Adds C(--clean-deps) option to I(zypper) remove command.
|
||||||
version_added: '4.6.0'
|
version_added: '4.6.0'
|
||||||
|
simple_errors:
|
||||||
|
type: bool
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
description:
|
||||||
|
- When set to V(true), provide a simplified error output (parses only the C(<message>) tag text in the XML output).
|
||||||
|
version_added: '10.2.0'
|
||||||
|
quiet:
|
||||||
|
type: bool
|
||||||
|
required: false
|
||||||
|
default: true
|
||||||
|
description:
|
||||||
|
- Adds C(--quiet) option to I(zypper) install/update command.
|
||||||
|
version_added: '10.2.0'
|
||||||
notes:
|
notes:
|
||||||
- When used with a C(loop:) each package will be processed individually, it is much more efficient to pass the list directly to the O(name)
|
- When used with a C(loop:) each package will be processed individually, it is much more efficient to pass the list directly to the O(name)
|
||||||
option.
|
option.
|
||||||
|
@ -190,6 +204,13 @@ EXAMPLES = r"""
|
||||||
name: '*'
|
name: '*'
|
||||||
state: latest
|
state: latest
|
||||||
|
|
||||||
|
- name: Install latest packages but dump error messages in a simplified format
|
||||||
|
community.general.zypper:
|
||||||
|
name: '*'
|
||||||
|
state: latest
|
||||||
|
simple_errors: true
|
||||||
|
quiet: false
|
||||||
|
|
||||||
- name: Apply all available patches
|
- name: Apply all available patches
|
||||||
community.general.zypper:
|
community.general.zypper:
|
||||||
name: '*'
|
name: '*'
|
||||||
|
@ -347,15 +368,38 @@ def parse_zypper_xml(m, cmd, fail_not_found=True, packages=None):
|
||||||
# run zypper again with the same command to complete update
|
# run zypper again with the same command to complete update
|
||||||
return parse_zypper_xml(m, cmd, fail_not_found=fail_not_found, packages=packages)
|
return parse_zypper_xml(m, cmd, fail_not_found=fail_not_found, packages=packages)
|
||||||
|
|
||||||
|
# apply simple_errors logic to rc 0,102,103,106
|
||||||
|
if m.params['simple_errors']:
|
||||||
|
stdout = get_simple_errors(dom) or stdout
|
||||||
|
|
||||||
return packages, rc, stdout, stderr
|
return packages, rc, stdout, stderr
|
||||||
|
|
||||||
|
# apply simple_errors logic to rc other than 0,102,103,106
|
||||||
|
if m.params['simple_errors']:
|
||||||
|
stdout = get_simple_errors(dom) or stdout
|
||||||
|
|
||||||
m.fail_json(msg='Zypper run command failed with return code %s.' % rc, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
|
m.fail_json(msg='Zypper run command failed with return code %s.' % rc, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def get_simple_errors(dom):
|
||||||
|
simple_errors = []
|
||||||
|
message_xml_tags = dom.getElementsByTagName('message')
|
||||||
|
|
||||||
|
if message_xml_tags is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
for x in message_xml_tags:
|
||||||
|
simple_errors.append(x.firstChild.data)
|
||||||
|
return " \n".join(simple_errors)
|
||||||
|
|
||||||
|
|
||||||
def get_cmd(m, subcommand):
|
def get_cmd(m, subcommand):
|
||||||
"puts together the basic zypper command arguments with those passed to the module"
|
"puts together the basic zypper command arguments with those passed to the module"
|
||||||
is_install = subcommand in ['install', 'update', 'patch', 'dist-upgrade']
|
is_install = subcommand in ['install', 'update', 'patch', 'dist-upgrade']
|
||||||
is_refresh = subcommand == 'refresh'
|
is_refresh = subcommand == 'refresh'
|
||||||
cmd = [m.get_bin_path('zypper', required=True), '--quiet', '--non-interactive', '--xmlout']
|
cmd = [m.get_bin_path('zypper', required=True), '--non-interactive', '--xmlout']
|
||||||
|
if m.params['quiet']:
|
||||||
|
cmd.append('--quiet')
|
||||||
if transactional_updates():
|
if transactional_updates():
|
||||||
cmd = [m.get_bin_path('transactional-update', required=True), '--continue', '--drop-if-no-change', '--quiet', 'run'] + cmd
|
cmd = [m.get_bin_path('transactional-update', required=True), '--continue', '--drop-if-no-change', '--quiet', 'run'] + cmd
|
||||||
if m.params['extra_args_precommand']:
|
if m.params['extra_args_precommand']:
|
||||||
|
@ -555,6 +599,8 @@ def main():
|
||||||
allow_vendor_change=dict(required=False, default=False, type='bool'),
|
allow_vendor_change=dict(required=False, default=False, type='bool'),
|
||||||
replacefiles=dict(required=False, default=False, type='bool'),
|
replacefiles=dict(required=False, default=False, type='bool'),
|
||||||
clean_deps=dict(required=False, default=False, type='bool'),
|
clean_deps=dict(required=False, default=False, type='bool'),
|
||||||
|
simple_errors=dict(required=False, default=False, type='bool'),
|
||||||
|
quiet=dict(required=False, default=True, type='bool'),
|
||||||
),
|
),
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue