From f46e19371823bd158dd361441608f036e00cfadf Mon Sep 17 00:00:00 2001 From: "t.goto" Date: Tue, 15 Mar 2016 16:12:56 +0900 Subject: [PATCH 1/2] change host.delete() parameter for newer ZBX api. As of Zabbix API 2.4, host.delete() will not takes parameter with `hostid` property but only the array of it. https://www.zabbix.com/documentation/2.2/manual/api/reference/host/delete fix #1800 --- monitoring/zabbix_host.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/monitoring/zabbix_host.py b/monitoring/zabbix_host.py index c75e53ee10f..f8ca93a6c45 100644 --- a/monitoring/zabbix_host.py +++ b/monitoring/zabbix_host.py @@ -26,7 +26,7 @@ short_description: Zabbix host creates/updates/deletes description: - This module allows you to create, modify and delete Zabbix host entries and associated group and template data. version_added: "2.0" -author: +author: - "(@cove)" - "Tony Minfei Ding" - "Harrison Gu (@harrisongu)" @@ -240,7 +240,7 @@ class Host(object): try: if self._module.check_mode: self._module.exit_json(changed=True) - self._zapi.host.delete({'hostid': host_id}) + self._zapi.host.delete([host_id]) except Exception, e: self._module.fail_json(msg="Failed to delete host %s: %s" % (host_name, e)) @@ -440,7 +440,7 @@ def main(): proxy_id = host.get_proxyid_by_proxy_name(proxy) else: proxy_id = None - + # get host id by host name zabbix_host_obj = host.get_host_by_host_name(host_name) host_id = zabbix_host_obj['hostid'] @@ -505,4 +505,3 @@ def main(): from ansible.module_utils.basic import * main() - From c19a721765fa86570ca7c689f99a2f83e1fdc624 Mon Sep 17 00:00:00 2001 From: "t.goto" Date: Tue, 15 Mar 2016 16:19:08 +0900 Subject: [PATCH 2/2] add exit_json add exit_json code to succesfully exit, when you want to delete the already deleted host. Without this, playbook fails with `Specify at least one group for creating host` which is not correct message. --- monitoring/zabbix_host.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monitoring/zabbix_host.py b/monitoring/zabbix_host.py index f8ca93a6c45..f3bc5e37527 100644 --- a/monitoring/zabbix_host.py +++ b/monitoring/zabbix_host.py @@ -485,6 +485,10 @@ def main(): else: module.exit_json(changed=False) else: + if state == "absent": + # the host is already deleted. + module.exit_json(changed=False) + # Use proxy specified, or set to 0 when adding new host if proxy: proxy_id = host.get_proxyid_by_proxy_name(proxy)