From 955f8923e7e7fff40eece3396908c42ecadadbc8 Mon Sep 17 00:00:00 2001 From: Ronny Date: Wed, 28 Jun 2017 17:48:27 +0200 Subject: [PATCH] Update dynamic inventory zabbix.py (#19862) Added _meta to improve the speed when using this dynamic inventory file --- contrib/inventory/zabbix.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/contrib/inventory/zabbix.py b/contrib/inventory/zabbix.py index 4bc472856f3..2a642d4d120 100755 --- a/contrib/inventory/zabbix.py +++ b/contrib/inventory/zabbix.py @@ -24,10 +24,12 @@ Zabbix Server external inventory script. ======================================== Returns hosts and hostgroups from Zabbix Server. +If you want to run with --limit against a host group with space in the +name, use asterisk. For example --limit="Linux*servers". Configuration is read from `zabbix.ini`. -Tested with Zabbix Server 2.0.6. +Tested with Zabbix Server 2.0.6 and 3.2.3. """ from __future__ import print_function @@ -102,14 +104,18 @@ class ZabbixInventory(object): data[groupname]['hosts'].append(hostname) + # Prevents Ansible from calling this script for each server with --host + data['_meta'] = { 'hostvars': self.meta } + return data def __init__(self): - self.defaultgroup = 'group_all' - self.zabbix_server = None + self.defaultgroup = 'group_all' + self.zabbix_server = None self.zabbix_username = None self.zabbix_password = None + self.meta = {} self.read_settings() self.read_cli()