From 0647d096023fa62c482aac9b47bc6584f38e24a4 Mon Sep 17 00:00:00 2001 From: Dusan Matejka Date: Mon, 11 Sep 2017 17:14:22 +0200 Subject: [PATCH] =?UTF-8?q?adds=20soft-update=20logic=20if=20force=20is=20?= =?UTF-8?q?set=20to=20no=20in=20zabbix=5Fhost=20module=20in=E2=80=A6=20(#2?= =?UTF-8?q?2614)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- lib/ansible/modules/monitoring/zabbix_host.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/monitoring/zabbix_host.py b/lib/ansible/modules/monitoring/zabbix_host.py index bbb4125c1d7..c4f99ec8cad 100644 --- a/lib/ansible/modules/monitoring/zabbix_host.py +++ b/lib/ansible/modules/monitoring/zabbix_host.py @@ -617,7 +617,26 @@ def main(): module.fail_json(msg="Specify at least one group for updating host '%s'." % host_name) 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 exist_interfaces = host._zapi.hostinterface.get({'output': 'extend', 'hostids': host_id})