multiple modules: improve dict.items() loops (#8876)
* multiple modules: improve dict.items() loops * simplify in memset_* modules * add changelog fragpull/8886/head
parent
80f48cceb4
commit
6af74d1ba6
|
@ -0,0 +1,16 @@
|
|||
minor_changes:
|
||||
- gitlab_deploy_key - better construct when using ``dict.items()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- gitlab_group - better construct when using ``dict.items()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- gitlab_issue - better construct when using ``dict.items()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- gitlab_merge_request - better construct when using ``dict.items()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- gitlab_runner - better construct when using ``dict.items()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- icinga2_host - replace loop with dict comprehension (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- memset_dns_reload - replace loop with ``dict()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- memset_memstore_info - replace loop with ``dict()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- memset_server_info - replace loop with ``dict()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- memset_zone - replace loop with ``dict()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- memset_zone_domain - replace loop with ``dict()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- memset_zone_record - replace loop with ``dict()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- nmcli - better construct when using ``dict.items()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- scaleway_user_data - better construct when using ``dict.items()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
||||
- udm_dns_record - replace loop with ``dict.update()`` (https://github.com/ansible-collections/community.general/pull/8876).
|
|
@ -196,9 +196,9 @@ class GitLabDeployKey(object):
|
|||
changed = False
|
||||
|
||||
for arg_key, arg_value in arguments.items():
|
||||
if arguments[arg_key] is not None:
|
||||
if getattr(deploy_key, arg_key) != arguments[arg_key]:
|
||||
setattr(deploy_key, arg_key, arguments[arg_key])
|
||||
if arg_value is not None:
|
||||
if getattr(deploy_key, arg_key) != arg_value:
|
||||
setattr(deploy_key, arg_key, arg_value)
|
||||
changed = True
|
||||
|
||||
return (changed, deploy_key)
|
||||
|
|
|
@ -277,9 +277,9 @@ class GitLabGroup(object):
|
|||
changed = False
|
||||
|
||||
for arg_key, arg_value in arguments.items():
|
||||
if arguments[arg_key] is not None:
|
||||
if getattr(group, arg_key) != arguments[arg_key]:
|
||||
setattr(group, arg_key, arguments[arg_key])
|
||||
if arg_value is not None:
|
||||
if getattr(group, arg_key) != arg_value:
|
||||
setattr(group, arg_key, arg_value)
|
||||
changed = True
|
||||
|
||||
return (changed, group)
|
||||
|
|
|
@ -264,14 +264,14 @@ class GitlabIssue(object):
|
|||
|
||||
if key == 'milestone_id':
|
||||
old_milestone = getattr(issue, 'milestone')['id'] if getattr(issue, 'milestone') else ""
|
||||
if options[key] != old_milestone:
|
||||
if value != old_milestone:
|
||||
return True
|
||||
elif key == 'assignee_ids':
|
||||
if options[key] != sorted([user["id"] for user in getattr(issue, 'assignees')]):
|
||||
if value != sorted([user["id"] for user in getattr(issue, 'assignees')]):
|
||||
return True
|
||||
|
||||
elif key == 'labels':
|
||||
if options[key] != sorted(getattr(issue, key)):
|
||||
if value != sorted(getattr(issue, key)):
|
||||
return True
|
||||
|
||||
elif getattr(issue, key) != value:
|
||||
|
|
|
@ -263,15 +263,15 @@ class GitlabMergeRequest(object):
|
|||
key = 'force_remove_source_branch'
|
||||
|
||||
if key == 'assignee_ids':
|
||||
if options[key] != sorted([user["id"] for user in getattr(mr, 'assignees')]):
|
||||
if value != sorted([user["id"] for user in getattr(mr, 'assignees')]):
|
||||
return True
|
||||
|
||||
elif key == 'reviewer_ids':
|
||||
if options[key] != sorted([user["id"] for user in getattr(mr, 'reviewers')]):
|
||||
if value != sorted([user["id"] for user in getattr(mr, 'reviewers')]):
|
||||
return True
|
||||
|
||||
elif key == 'labels':
|
||||
if options[key] != sorted(getattr(mr, key)):
|
||||
if value != sorted(getattr(mr, key)):
|
||||
return True
|
||||
|
||||
elif getattr(mr, key) != value:
|
||||
|
|
|
@ -368,18 +368,18 @@ class GitLabRunner(object):
|
|||
changed = False
|
||||
|
||||
for arg_key, arg_value in arguments.items():
|
||||
if arguments[arg_key] is not None:
|
||||
if isinstance(arguments[arg_key], list):
|
||||
if arg_value is not None:
|
||||
if isinstance(arg_value, list):
|
||||
list1 = getattr(runner, arg_key)
|
||||
list1.sort()
|
||||
list2 = arguments[arg_key]
|
||||
list2 = arg_value
|
||||
list2.sort()
|
||||
if list1 != list2:
|
||||
setattr(runner, arg_key, arguments[arg_key])
|
||||
setattr(runner, arg_key, arg_value)
|
||||
changed = True
|
||||
else:
|
||||
if getattr(runner, arg_key) != arguments[arg_key]:
|
||||
setattr(runner, arg_key, arguments[arg_key])
|
||||
if getattr(runner, arg_key) != arg_value:
|
||||
setattr(runner, arg_key, arg_value)
|
||||
changed = True
|
||||
|
||||
return (changed, runner)
|
||||
|
|
|
@ -282,9 +282,7 @@ def main():
|
|||
'vars.made_by': "ansible"
|
||||
}
|
||||
}
|
||||
|
||||
for key, value in variables.items():
|
||||
data['attrs']['vars.' + key] = value
|
||||
data['attrs'].update({'vars.' + key: value for key, value in variables.items()})
|
||||
|
||||
changed = False
|
||||
if icinga.exists(name):
|
||||
|
|
|
@ -178,9 +178,7 @@ def main():
|
|||
)
|
||||
|
||||
# populate the dict with the user-provided vars.
|
||||
args = dict()
|
||||
for key, arg in module.params.items():
|
||||
args[key] = arg
|
||||
args = dict(module.params)
|
||||
|
||||
retvals = reload_dns(args)
|
||||
|
||||
|
|
|
@ -163,9 +163,7 @@ def main():
|
|||
)
|
||||
|
||||
# populate the dict with the user-provided vars.
|
||||
args = dict()
|
||||
for key, arg in module.params.items():
|
||||
args[key] = arg
|
||||
args = dict(module.params)
|
||||
|
||||
retvals = get_facts(args)
|
||||
|
||||
|
|
|
@ -288,9 +288,7 @@ def main():
|
|||
)
|
||||
|
||||
# populate the dict with the user-provided vars.
|
||||
args = dict()
|
||||
for key, arg in module.params.items():
|
||||
args[key] = arg
|
||||
args = dict(module.params)
|
||||
|
||||
retvals = get_facts(args)
|
||||
|
||||
|
|
|
@ -300,9 +300,7 @@ def main():
|
|||
)
|
||||
|
||||
# populate the dict with the user-provided vars.
|
||||
args = dict()
|
||||
for key, arg in module.params.items():
|
||||
args[key] = arg
|
||||
args = dict(module.params)
|
||||
args['check_mode'] = module.check_mode
|
||||
|
||||
# validate some API-specific limitations.
|
||||
|
|
|
@ -244,9 +244,7 @@ def main():
|
|||
)
|
||||
|
||||
# populate the dict with the user-provided vars.
|
||||
args = dict()
|
||||
for key, arg in module.params.items():
|
||||
args[key] = arg
|
||||
args = dict(module.params)
|
||||
args['check_mode'] = module.check_mode
|
||||
|
||||
# validate some API-specific limitations.
|
||||
|
|
|
@ -374,9 +374,7 @@ def main():
|
|||
)
|
||||
|
||||
# populate the dict with the user-provided vars.
|
||||
args = dict()
|
||||
for key, arg in module.params.items():
|
||||
args[key] = arg
|
||||
args = dict(module.params)
|
||||
args['check_mode'] = module.check_mode
|
||||
|
||||
# perform some Memset API-specific validation
|
||||
|
|
|
@ -1944,7 +1944,7 @@ class Nmcli(object):
|
|||
convert_func = self.list_to_string
|
||||
|
||||
if callable(convert_func):
|
||||
options[setting] = convert_func(options[setting])
|
||||
options[setting] = convert_func(value)
|
||||
|
||||
return options
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ def core(module):
|
|||
|
||||
# Then we patch keys that are different
|
||||
for key, value in user_data.items():
|
||||
if key not in present_user_data or user_data[key] != present_user_data[key]:
|
||||
if key not in present_user_data or value != present_user_data[key]:
|
||||
|
||||
changed = True
|
||||
if compute_api.module.check_mode:
|
||||
|
|
|
@ -196,8 +196,7 @@ def main():
|
|||
else:
|
||||
obj['name'] = name
|
||||
|
||||
for k, v in data.items():
|
||||
obj[k] = v
|
||||
obj.update(data)
|
||||
diff = obj.diff()
|
||||
changed = obj.diff() != []
|
||||
if not module.check_mode:
|
||||
|
|
Loading…
Reference in New Issue