Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zypper_repository: preserve attributes enabled, autorefresh and gpgcheck if provided from the task parameters #9108

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- zypper-module - only read attributes ``enabled``, ``disable_gpg_check`` and ``autorefresh`` from local repo files, if the parameters weren't already provided by the task parameters
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- zypper-module - only read attributes ``enabled``, ``disable_gpg_check`` and ``autorefresh`` from local repo files, if the parameters weren't already provided by the task parameters
- zypper-module - only read attributes ``enabled``, ``disable_gpg_check`` and ``autorefresh`` from local repo files, if the parameters were not already provided by the task parameters (https://github.com/ansible-collections/community.general/pull/9108).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @TobiasZeuch181 please add this modification as well.

40 changes: 27 additions & 13 deletions plugins/modules/zypper_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,6 @@ def main():
'name': module.params['description'],
'priority': module.params['priority'],
}
# rewrite bools in the language that zypper lr -x provides for easier comparison
if module.params['enabled']:
repodata['enabled'] = '1'
else:
repodata['enabled'] = '0'
if module.params['disable_gpg_check']:
repodata['gpgcheck'] = '0'
else:
repodata['gpgcheck'] = '1'
if module.params['autorefresh']:
repodata['autorefresh'] = '1'
else:
repodata['autorefresh'] = '0'

def exit_unchanged():
module.exit_json(changed=False, repodata=repodata, state=state)
Expand All @@ -393,6 +380,15 @@ def exit_unchanged():
if not alias and state == "present":
module.fail_json(msg='Name required when adding non-repo files.')


TobiasZeuch181 marked this conversation as resolved.
Show resolved Hide resolved
# fill boolean attributes with defaults
if 'enabled' not in repodata:
repodata['enabled'] = '0'
if 'autorefresh' not in repodata:
repodata['autorefresh'] = '0'
if 'gpgcheck' not in repodata:
repodata['gpgcheck'] = '0'

# Download / Open and parse .repo file to ensure idempotency
if repo and repo.endswith('.repo'):
if repo.startswith(('http://', 'https://')):
Expand Down Expand Up @@ -443,6 +439,24 @@ def exit_unchanged():
if 'gpgcheck' in repofile_items:
repodata['gpgcheck'] = repofile_items['gpgcheck']

# override boolean parameters in repodata with provided entries in module.params
# in the language that zypper lr -x provides for easier comparison
if 'enabled' in module.params:
if module.params['enabled']:
repodata['enabled'] = '1'
else:
repodata['enabled'] = '0'
if 'disable_gpg_check' in module.params:
if module.params['disable_gpg_check']:
repodata['gpgcheck'] = '0'
else:
repodata['gpgcheck'] = '1'
if 'autorefresh' in module.params:
if module.params['autorefresh']:
repodata['autorefresh'] = '1'
else:
repodata['autorefresh'] = '0'
Comment on lines +443 to +457
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check if the key exists, however, is redundant. They will always exist. Please simplify this to:

Suggested change
if 'enabled' in module.params:
if module.params['enabled']:
repodata['enabled'] = '1'
else:
repodata['enabled'] = '0'
if 'disable_gpg_check' in module.params:
if module.params['disable_gpg_check']:
repodata['gpgcheck'] = '0'
else:
repodata['gpgcheck'] = '1'
if 'autorefresh' in module.params:
if module.params['autorefresh']:
repodata['autorefresh'] = '1'
else:
repodata['autorefresh'] = '0'
repodata['enabled'] = '1' if module.params['enabled'] else '0'
repodata['gpgcheck'] = '0' if module.params['disable_gpg_check'] else '1'
repodata['autorefresh'] = '1' if module.params['autorefresh'] else '0'


exists, mod, old_repos = repo_exists(module, repodata, overwrite_multiple)

if alias:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,44 @@
that:
- added_again_by_repo_file is not changed

- name: change the repository config by name with flag - disable
community.general.zypper_repository:
name: systemsmanagement_Uyuni_Stable
state: present
enabled: false
register: modified_repo_file_result

- name: modified_repo_file_result is changed
assert:
that:
- modified_repo_file_result is changed

- name: get repository details again from zypper after disabling the repository
command: zypper --xmlout lr systemsmanagement_Uyuni_Stable
register: get_repository_details_from_zypper

- name: verify modifying via .repo file was successful - the module is now disabled
assert:
that:
- "'enabled=\"0\"' in get_repository_details_from_zypper.stdout"

- name: change flag autorefresh in the same zypper-module
community.general.zypper_repository:
name: systemsmanagement_Uyuni_Stable
state: present
autorefresh: false
register: modified_repo_file_result

- name: get repository details again from zypper after disabling the repository
command: zypper --xmlout lr systemsmanagement_Uyuni_Stable
register: get_repository_details_from_zypper

- name: verify modifying via .repo file was successful - the autorefesh is disabled, but the enabled-flag was not modified (it is still disabled)
assert:
that:
- "'enabled=\"0\"' in get_repository_details_from_zypper.stdout"
- "'autorefresh=\"0\"' in get_repository_details_from_zypper.stdout"

- name: remove repository via url to .repo file
community.general.zypper_repository:
repo: http://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Stable/openSUSE_Leap_{{ ansible_distribution_version }}/systemsmanagement:Uyuni:Stable.repo
Expand Down
Loading