zabbix_host : add the ability to set inventory_mode
This commit is contained in:
parent
45bba8ec64
commit
1a29807e96
1 changed files with 34 additions and 0 deletions
|
@ -61,6 +61,13 @@ options:
|
||||||
- List of templates linked to the host.
|
- List of templates linked to the host.
|
||||||
required: false
|
required: false
|
||||||
default: None
|
default: None
|
||||||
|
inventory_mode:
|
||||||
|
description:
|
||||||
|
- Configure the inventory mode.
|
||||||
|
choices: ['automatic', 'manual', 'disabled']
|
||||||
|
required: false
|
||||||
|
default: None
|
||||||
|
version_added: '2.1'
|
||||||
status:
|
status:
|
||||||
description:
|
description:
|
||||||
- Monitoring status of the host.
|
- Monitoring status of the host.
|
||||||
|
@ -116,6 +123,7 @@ EXAMPLES = '''
|
||||||
- Example template2
|
- Example template2
|
||||||
status: enabled
|
status: enabled
|
||||||
state: present
|
state: present
|
||||||
|
inventory_mode: automatic
|
||||||
interfaces:
|
interfaces:
|
||||||
- type: 1
|
- type: 1
|
||||||
main: 1
|
main: 1
|
||||||
|
@ -367,6 +375,28 @@ class Host(object):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self._module.fail_json(msg="Failed to link template to host: %s" % e)
|
self._module.fail_json(msg="Failed to link template to host: %s" % e)
|
||||||
|
|
||||||
|
# Update the host inventory_mode
|
||||||
|
def update_inventory_mode(self, host_id, inventory_mode):
|
||||||
|
|
||||||
|
# nothing was set, do nothing
|
||||||
|
if not inventory_mode:
|
||||||
|
return
|
||||||
|
|
||||||
|
if inventory_mode == "automatic":
|
||||||
|
inventory_mode = int(1)
|
||||||
|
elif inventory_mode == "manual":
|
||||||
|
inventory_mode = int(0)
|
||||||
|
elif inventory_mode == "disabled":
|
||||||
|
inventory_mode = int(-1)
|
||||||
|
|
||||||
|
# watch for - https://support.zabbix.com/browse/ZBX-6033
|
||||||
|
request_str = {'hostid': host_id, 'inventory_mode': inventory_mode}
|
||||||
|
try:
|
||||||
|
if self._module.check_mode:
|
||||||
|
self._module.exit_json(changed=True)
|
||||||
|
self._zapi.host.update(request_str)
|
||||||
|
except Exception, e:
|
||||||
|
self._module.fail_json(msg="Failed to set inventory_mode to host: %s" % e)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -379,6 +409,7 @@ def main():
|
||||||
link_templates=dict(type='list', required=False),
|
link_templates=dict(type='list', required=False),
|
||||||
status=dict(default="enabled", choices=['enabled', 'disabled']),
|
status=dict(default="enabled", choices=['enabled', 'disabled']),
|
||||||
state=dict(default="present", choices=['present', 'absent']),
|
state=dict(default="present", choices=['present', 'absent']),
|
||||||
|
inventory_mode=dict(required=False, choices=['automatic', 'manual', 'disabled']),
|
||||||
timeout=dict(type='int', default=10),
|
timeout=dict(type='int', default=10),
|
||||||
interfaces=dict(type='list', required=False),
|
interfaces=dict(type='list', required=False),
|
||||||
force=dict(type='bool', default=True),
|
force=dict(type='bool', default=True),
|
||||||
|
@ -396,6 +427,7 @@ def main():
|
||||||
host_name = module.params['host_name']
|
host_name = module.params['host_name']
|
||||||
host_groups = module.params['host_groups']
|
host_groups = module.params['host_groups']
|
||||||
link_templates = module.params['link_templates']
|
link_templates = module.params['link_templates']
|
||||||
|
inventory_mode = module.params['inventory_mode']
|
||||||
status = module.params['status']
|
status = module.params['status']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
timeout = module.params['timeout']
|
timeout = module.params['timeout']
|
||||||
|
@ -479,6 +511,7 @@ def main():
|
||||||
exist_interfaces_copy, zabbix_host_obj, proxy_id):
|
exist_interfaces_copy, zabbix_host_obj, proxy_id):
|
||||||
host.update_host(host_name, group_ids, status, host_id, interfaces, exist_interfaces, proxy_id)
|
host.update_host(host_name, group_ids, status, host_id, interfaces, exist_interfaces, proxy_id)
|
||||||
host.link_or_clear_template(host_id, template_ids)
|
host.link_or_clear_template(host_id, template_ids)
|
||||||
|
host.update_inventory_mode(host_id, inventory_mode)
|
||||||
module.exit_json(changed=True,
|
module.exit_json(changed=True,
|
||||||
result="Successfully update host %s (%s) and linked with template '%s'"
|
result="Successfully update host %s (%s) and linked with template '%s'"
|
||||||
% (host_name, ip, link_templates))
|
% (host_name, ip, link_templates))
|
||||||
|
@ -500,6 +533,7 @@ def main():
|
||||||
# create host
|
# create host
|
||||||
host_id = host.add_host(host_name, group_ids, status, interfaces, proxy_id)
|
host_id = host.add_host(host_name, group_ids, status, interfaces, proxy_id)
|
||||||
host.link_or_clear_template(host_id, template_ids)
|
host.link_or_clear_template(host_id, template_ids)
|
||||||
|
host.update_inventory_mode(host_id, inventory_mode)
|
||||||
module.exit_json(changed=True, result="Successfully added host %s (%s) and linked with template '%s'" % (
|
module.exit_json(changed=True, result="Successfully added host %s (%s) and linked with template '%s'" % (
|
||||||
host_name, ip, link_templates))
|
host_name, ip, link_templates))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue