summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDusan Matejka <D3DeFi@users.noreply.github.com>2017-09-11 17:14:22 +0200
committerChris Alfonso <christopher.alfonso@gmail.com>2017-09-11 09:14:22 -0600
commit0647d096023fa62c482aac9b47bc6584f38e24a4 (patch)
treecdbc82f04f2fd04da83a1526efd2881fdd486a46
parent81f76475f1fd28b88fa4e0256cc5c00346b2af37 (diff)
downloadansible-0647d096023fa62c482aac9b47bc6584f38e24a4.tar.gz
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
-rw-r--r--lib/ansible/modules/monitoring/zabbix_host.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/ansible/modules/monitoring/zabbix_host.py b/lib/ansible/modules/monitoring/zabbix_host.py
index bbb4125c1d..c4f99ec8ca 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})