1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

adds soft-update logic if force is set to no in zabbix_host module in… (#22614)

* adds soft-update logic if force is set to no in zabbix_host module instead of failing

* makes zabbix_host soft-update compatible with python2.6
This commit is contained in:
Dusan Matejka 2017-09-11 17:14:22 +02:00 committed by Chris Alfonso
parent 81f76475f1
commit 0647d09602

View file

@ -617,7 +617,26 @@ def main():
module.fail_json(msg="Specify at least one group for updating host '%s'." % host_name) module.fail_json(msg="Specify at least one group for updating host '%s'." % host_name)
if not force: if not force:
module.fail_json(changed=False, result="Host present, Can't update configuration without force") # get existing groups, interfaces and templates and merge them with ones provided as an argument
# we do not want to overwrite anything if force: no is explicitly used, we just want to add new ones
for group_id in host.get_group_ids_by_group_names(host.get_host_groups_by_host_id(host_id)):
if group_id not in group_ids:
group_ids.append(group_id)
for interface in host._zapi.hostinterface.get({'output': 'extend', 'hostids': host_id}):
# remove values not used during hostinterface.add/update calls
for key in interface.keys():
if key in ['interfaceid', 'hostid', 'bulk']:
interface.pop(key, None)
for index in interface.keys():
if index in ['useip', 'main', 'type', 'port']:
interface[index] = int(interface[index])
if interface not in interfaces:
interfaces.append(interface)
template_ids = list(set(template_ids + host.get_host_templates_by_host_id(host_id)))
# get exist host's interfaces # get exist host's interfaces
exist_interfaces = host._zapi.hostinterface.get({'output': 'extend', 'hostids': host_id}) exist_interfaces = host._zapi.hostinterface.get({'output': 'extend', 'hostids': host_id})