mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-09 12:10:31 -07:00
Reordering how the boolean parameters are filled
I think, this is the right approach: # fill the boolean entries with default # override the values with what is found in the repo-file (remote or locally on the file) # finally override the values with what is provided in the module-params then we can check if the data has changed compared to the local data
This commit is contained in:
parent
ba8eca9488
commit
a016d5b271
1 changed files with 30 additions and 31 deletions
|
@ -356,22 +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 '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'
|
||||
|
||||
def exit_unchanged():
|
||||
module.exit_json(changed=False, repodata=repodata, state=state)
|
||||
|
@ -396,6 +380,15 @@ def main():
|
|||
if not alias and state == "present":
|
||||
module.fail_json(msg='Name required when adding non-repo files.')
|
||||
|
||||
|
||||
# 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://')):
|
||||
|
@ -438,25 +431,31 @@ def main():
|
|||
|
||||
# Map additional values, if available
|
||||
if 'name' in repofile_items:
|
||||
if 'name' not in repodata:
|
||||
repodata['name'] = repofile_items['name']
|
||||
repodata['name'] = repofile_items['name']
|
||||
if 'enabled' in repofile_items:
|
||||
if 'enabled' not in repodata:
|
||||
repodata['enabled'] = repofile_items['enabled']
|
||||
repodata['enabled'] = repofile_items['enabled']
|
||||
if 'autorefresh' in repofile_items:
|
||||
if 'autorefresh' not in repodata:
|
||||
repodata['autorefresh'] = repofile_items['autorefresh']
|
||||
repodata['autorefresh'] = repofile_items['autorefresh']
|
||||
if 'gpgcheck' in repofile_items:
|
||||
if 'gpgcheck' not in repodata:
|
||||
repodata['gpgcheck'] = repofile_items['gpgcheck']
|
||||
repodata['gpgcheck'] = repofile_items['gpgcheck']
|
||||
|
||||
# finally, fill empty 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'
|
||||
# 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'
|
||||
|
||||
exists, mod, old_repos = repo_exists(module, repodata, overwrite_multiple)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue