Added Support for creating a Zabbix Inventory. It is possible to tag the (#23792)
* Rebase with update of remote repository * Add Example * Reference to example * Fix error with collon (ansibot saw a yaml not a string) * Change inventory mode to manual add link to inventory documentation of zabbix * Fix: The test ansible-test sanity --test pep8 [?] failed with the following error: lib/ansible/modules/monitoring/zabbix_host.py:532:1: E302 expected 2 blank lines, found 1 The test ansible-test sanity --test validate-modules [?] failed with the following error: lib/ansible/modules/monitoring/zabbix_host.py:0:0: E309 version_added for new option (inventory_zabbix) should be 2.5. Currently 2.4
This commit is contained in:
parent
2fb8df503e
commit
98eac19e81
1 changed files with 34 additions and 1 deletions
|
@ -60,6 +60,14 @@ options:
|
|||
required: false
|
||||
default: None
|
||||
version_added: '2.1'
|
||||
inventory_zabbix:
|
||||
description:
|
||||
- Add Facts for a zabbix inventory (e.g. Tag) (see example below).
|
||||
- Please review the interface documentation for more information on the supported properties
|
||||
- 'https://www.zabbix.com/documentation/3.2/manual/api/reference/host/object#host_inventory'
|
||||
required: false
|
||||
default: None
|
||||
version_added: '2.5'
|
||||
status:
|
||||
description:
|
||||
- Monitoring status of the host.
|
||||
|
@ -160,7 +168,15 @@ EXAMPLES = '''
|
|||
- Example template2
|
||||
status: enabled
|
||||
state: present
|
||||
inventory_mode: automatic
|
||||
inventory_mode: manual
|
||||
inventory_zabbix:
|
||||
tag: "{{ your_tag }}"
|
||||
alias: "{{ your_alias }}"
|
||||
notes: "Special Informations: {{ your_informations | default('None') }}"
|
||||
location: "{{ your_location }}"
|
||||
site_rack: "{{ your_site_rack }}"
|
||||
os: "{{ your_os }}"
|
||||
hardware: "{{ your_hardware }}"
|
||||
interfaces:
|
||||
- type: 1
|
||||
main: 1
|
||||
|
@ -500,6 +516,19 @@ class Host(object):
|
|||
except Exception as e:
|
||||
self._module.fail_json(msg="Failed to set inventory_mode to host: %s" % e)
|
||||
|
||||
def update_inventory_zabbix(self, host_id, inventory):
|
||||
|
||||
if not inventory:
|
||||
return
|
||||
|
||||
request_str = {'hostid': host_id, 'inventory': inventory}
|
||||
try:
|
||||
if self._module.check_mode:
|
||||
self._module.exit_json(changed=True)
|
||||
self._zapi.host.update(request_str)
|
||||
except Exception as e:
|
||||
self._module.fail_json(msg="Failed to set inventory to host: %s" % e)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
|
@ -522,6 +551,7 @@ def main():
|
|||
tls_psk=dict(type='str', required=False),
|
||||
tls_issuer=dict(type='str', required=False),
|
||||
tls_subject=dict(type='str', required=False),
|
||||
inventory_zabbix=dict(required=False, type='dict'),
|
||||
timeout=dict(type='int', default=10),
|
||||
interfaces=dict(type='list', required=False),
|
||||
force=dict(type='bool', default=True),
|
||||
|
@ -553,6 +583,7 @@ def main():
|
|||
tls_psk = module.params['tls_psk']
|
||||
tls_issuer = module.params['tls_issuer']
|
||||
tls_subject = module.params['tls_subject']
|
||||
inventory_zabbix = module.params['inventory_zabbix']
|
||||
status = module.params['status']
|
||||
state = module.params['state']
|
||||
timeout = module.params['timeout']
|
||||
|
@ -662,6 +693,7 @@ def main():
|
|||
host.link_or_clear_template(host_id, template_ids, tls_connect, tls_accept, tls_psk_identity,
|
||||
tls_psk, tls_issuer, tls_subject)
|
||||
host.update_inventory_mode(host_id, inventory_mode)
|
||||
host.update_inventory_zabbix(host_id, inventory_zabbix)
|
||||
module.exit_json(changed=True,
|
||||
result="Successfully update host %s (%s) and linked with template '%s'"
|
||||
% (host_name, ip, link_templates))
|
||||
|
@ -690,6 +722,7 @@ def main():
|
|||
host.link_or_clear_template(host_id, template_ids, tls_connect, tls_accept, tls_psk_identity,
|
||||
tls_psk, tls_issuer, tls_subject)
|
||||
host.update_inventory_mode(host_id, inventory_mode)
|
||||
host.update_inventory_zabbix(host_id, inventory_zabbix)
|
||||
module.exit_json(changed=True, result="Successfully added host %s (%s) and linked with template '%s'" % (
|
||||
host_name, ip, link_templates))
|
||||
|
||||
|
|
Loading…
Reference in a new issue