allows user to not update zabbix host config if host is present.

This commit is contained in:
Ritesh Khadgaray 2015-11-09 20:21:28 +05:30 committed by Matt Clay
parent 9802112dd4
commit 83bf44c78f

View file

@ -88,6 +88,13 @@ options:
- 'https://www.zabbix.com/documentation/2.0/manual/appendix/api/hostinterface/definitions#host_interface' - 'https://www.zabbix.com/documentation/2.0/manual/appendix/api/hostinterface/definitions#host_interface'
required: false required: false
default: [] default: []
force:
description:
- Overwrite the host configuration, even if already present
required: false
default: "yes"
choices: [ "yes", "no" ]
version_added: "2.0"
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -367,6 +374,7 @@ def main():
state=dict(default="present", choices=['present', 'absent']), state=dict(default="present", choices=['present', 'absent']),
timeout=dict(type='int', default=10), timeout=dict(type='int', default=10),
interfaces=dict(required=False), interfaces=dict(required=False),
force=dict(default='yes', choices='bool'),
proxy=dict(required=False) proxy=dict(required=False)
), ),
supports_check_mode=True supports_check_mode=True
@ -385,6 +393,7 @@ def main():
state = module.params['state'] state = module.params['state']
timeout = module.params['timeout'] timeout = module.params['timeout']
interfaces = module.params['interfaces'] interfaces = module.params['interfaces']
force = module.params['force']
proxy = module.params['proxy'] proxy = module.params['proxy']
# convert enabled to 0; disabled to 1 # convert enabled to 0; disabled to 1
@ -436,6 +445,9 @@ def main():
if not group_ids: if not group_ids:
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:
module.fail_json(changed=False, result="Host present, Can't update configuration without force")
# 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})
exist_interfaces_copy = copy.deepcopy(exist_interfaces) exist_interfaces_copy = copy.deepcopy(exist_interfaces)