From 83bf44c78f14bb1c67beeeb15edb875cd241f7b9 Mon Sep 17 00:00:00 2001 From: Ritesh Khadgaray Date: Mon, 9 Nov 2015 20:21:28 +0530 Subject: [PATCH] allows user to not update zabbix host config if host is present. --- lib/ansible/modules/extras/monitoring/zabbix_host.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/ansible/modules/extras/monitoring/zabbix_host.py b/lib/ansible/modules/extras/monitoring/zabbix_host.py index b17a259039b..717baa6232e 100644 --- a/lib/ansible/modules/extras/monitoring/zabbix_host.py +++ b/lib/ansible/modules/extras/monitoring/zabbix_host.py @@ -88,6 +88,13 @@ options: - 'https://www.zabbix.com/documentation/2.0/manual/appendix/api/hostinterface/definitions#host_interface' required: false default: [] + force: + description: + - Overwrite the host configuration, even if already present + required: false + default: "yes" + choices: [ "yes", "no" ] + version_added: "2.0" ''' EXAMPLES = ''' @@ -367,6 +374,7 @@ def main(): state=dict(default="present", choices=['present', 'absent']), timeout=dict(type='int', default=10), interfaces=dict(required=False), + force=dict(default='yes', choices='bool'), proxy=dict(required=False) ), supports_check_mode=True @@ -385,6 +393,7 @@ def main(): state = module.params['state'] timeout = module.params['timeout'] interfaces = module.params['interfaces'] + force = module.params['force'] proxy = module.params['proxy'] # convert enabled to 0; disabled to 1 @@ -436,6 +445,9 @@ def main(): if not group_ids: 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 exist host's interfaces exist_interfaces = host._zapi.hostinterface.get({'output': 'extend', 'hostids': host_id}) exist_interfaces_copy = copy.deepcopy(exist_interfaces)