mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-13 03:25:34 +00:00
fix(zypper_repository): preserve .repo file settings when parameters are not explicitly provided
When enabled/autorefresh/disable_gpg_check are not provided by the user, fall back to values from the .repo file before applying hard defaults, so that existing tasks relying on the .repo file content are not broken. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
84498d4cc8
commit
3955e63196
1 changed files with 22 additions and 18 deletions
|
|
@ -45,13 +45,13 @@ options:
|
|||
description:
|
||||
- Whether to disable GPG signature checking of all packages. Has an effect only if O(state=present).
|
||||
- Needs C(zypper) version >= 1.6.2.
|
||||
- When not specified, the value from the C(.repo) file is used if available, otherwise it defaults to V(false).
|
||||
type: bool
|
||||
default: false
|
||||
autorefresh:
|
||||
description:
|
||||
- Enable autorefresh of the repository.
|
||||
- When not specified, the value from the C(.repo) file is used if available, otherwise it defaults to V(true).
|
||||
type: bool
|
||||
default: true
|
||||
aliases: ["refresh"]
|
||||
priority:
|
||||
description:
|
||||
|
|
@ -81,8 +81,8 @@ options:
|
|||
enabled:
|
||||
description:
|
||||
- Set repository to enabled (or disabled).
|
||||
- When not specified, the value from the C(.repo) file is used if available, otherwise it defaults to V(true).
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
|
||||
requirements:
|
||||
|
|
@ -328,10 +328,10 @@ def main():
|
|||
state=dict(choices=["present", "absent"], default="present"),
|
||||
runrefresh=dict(default=False, type="bool"),
|
||||
description=dict(),
|
||||
disable_gpg_check=dict(default=False, type="bool"),
|
||||
autorefresh=dict(default=True, type="bool", aliases=["refresh"]),
|
||||
disable_gpg_check=dict(type="bool"),
|
||||
autorefresh=dict(type="bool", aliases=["refresh"]),
|
||||
priority=dict(type="int"),
|
||||
enabled=dict(default=True, type="bool"),
|
||||
enabled=dict(type="bool"),
|
||||
overwrite_multiple=dict(default=False, type="bool"),
|
||||
auto_import_keys=dict(default=False, type="bool"),
|
||||
),
|
||||
|
|
@ -356,18 +356,13 @@ def main():
|
|||
"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"
|
||||
# only set if the user explicitly provided the parameter (None means unset)
|
||||
if module.params["enabled"] is not None:
|
||||
repodata["enabled"] = "1" if module.params["enabled"] else "0"
|
||||
if module.params["disable_gpg_check"] is not None:
|
||||
repodata["gpgcheck"] = "0" if module.params["disable_gpg_check"] else "1"
|
||||
if module.params["autorefresh"] is not None:
|
||||
repodata["autorefresh"] = "1" if module.params["autorefresh"] else "0"
|
||||
|
||||
def exit_unchanged():
|
||||
module.exit_json(changed=False, repodata=repodata, state=state)
|
||||
|
|
@ -451,6 +446,15 @@ def main():
|
|||
# Map additional values, if available
|
||||
if "name" in repofile_items:
|
||||
repodata["name"] = repofile_items["name"]
|
||||
# Use .repo file values only for settings the user did not explicitly provide
|
||||
for key in ("enabled", "autorefresh", "gpgcheck"):
|
||||
if key not in repodata and key in repofile_items:
|
||||
repodata[key] = repofile_items[key]
|
||||
|
||||
# Apply defaults for any settings not provided by the user or the .repo file
|
||||
repodata.setdefault("enabled", "1")
|
||||
repodata.setdefault("gpgcheck", "1")
|
||||
repodata.setdefault("autorefresh", "1")
|
||||
|
||||
exists, mod, old_repos = repo_exists(module, repodata, overwrite_multiple)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue