community.zabbix.zabbix_inventory – Zabbix Inventory Plugin

Note

This plugin is part of the community.zabbix collection (version 1.4.0).

To install it use: ansible-galaxy collection install community.zabbix.

To use it in a playbook, specify: community.zabbix.zabbix_inventory.

New in version 1.4.0: of community.zabbix

Synopsis

  • Zabbix Inventory plugin

  • All vars from zabbix are prefixed with zbx_

Requirements

The below requirements are needed on the local controller node that executes this inventory.

  • python >= 2.6

  • zabbix-api >= 0.5.4

Parameters

Parameter Choices/Defaults Configuration Comments
add_zabbix_groups
boolean
    Choices:
  • no ←
  • yes
If set to True, hosts will be added to groups based on their zabbix groups
cache
boolean
    Choices:
  • no ←
  • yes
ini entries:

[inventory]
cache = no

env:ANSIBLE_INVENTORY_CACHE
Toggle to enable/disable the caching of the inventory's source data, requires a cache plugin setup to work.
cache_connection
string
ini entries:

[defaults]
fact_caching_connection = None

[inventory]
cache_connection = None

env:ANSIBLE_CACHE_PLUGIN_CONNECTION
env:ANSIBLE_INVENTORY_CACHE_CONNECTION
Cache connection data or path, read cache plugin documentation for specifics.
cache_plugin
string
Default:
"memory"
ini entries:

[defaults]
fact_caching = memory

[inventory]
cache_plugin = memory

env:ANSIBLE_CACHE_PLUGIN
env:ANSIBLE_INVENTORY_CACHE_PLUGIN
Cache plugin to use for the inventory's source data.
cache_prefix
string
Default:
"ansible_inventory_"
ini entries:

[default]
fact_caching_prefix = ansible_inventory_

[inventory]
cache_prefix = ansible_inventory_

env:ANSIBLE_CACHE_PLUGIN_PREFIX
env:ANSIBLE_INVENTORY_CACHE_PLUGIN_PREFIX
Prefix to use for cache plugin files/tables
cache_timeout
integer
Default:
3600
ini entries:

[defaults]
fact_caching_timeout = 3600

[inventory]
cache_timeout = 3600

env:ANSIBLE_CACHE_PLUGIN_TIMEOUT
env:ANSIBLE_INVENTORY_CACHE_TIMEOUT
Cache duration in seconds
compose
dictionary
Default:
{}
Create vars from jinja2 expressions.
groups
dictionary
Default:
{}
Add hosts to group based on Jinja2 conditionals.
host_zapi_query
dictionary
Default:
[]
API query for hosts - see zabbix documentation for more details https://www.zabbix.com/documentation/current/manual/api/reference/host/get
selectApplications
string
query
Return an applications property with host applications.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectDashboards
string
query
Return a dashboards property.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectDiscoveries
string
query
Return a discoveries property with host low-level discovery rules.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectDiscoveryRule
string
query
Return a discoveryRule property with the low-level discovery rule that created the host (from host prototype in VMware monitoring).
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectGraphs
string
query
Return a discoveries property with host low-level discovery rules.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectGroups
string
query
Return a groups property with host groups data that the host belongs to.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectHostDiscovery
string
query
Return a hostDiscovery property with host discovery object data.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectHttpTests
string
query
Return an httpTests property with host web scenarios.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectInheritedTags
string
query
Return an inheritedTags property with tags that are on all templates which are linked to host.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectInterfaces
string
query
Return an interfaces property with host interfaces.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectInventory
string
query
Return an inventory property with host inventory data.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectItems
string
query
Return an items property with host items.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectMacros
string
query
Return a macros property with host macros.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectParentTemplates
string
query
Return a parentTemplates property with templates that the host is linked to
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectTags
string
query
Return a tags property with host tags.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
selectTriggers
string
query
Return a triggers property with host triggers.
To return all values specify 'extend'
Can be limited to different fields for example setting the vaule to ['name'] will only return the name
Additional fields can be specified by comma seperated value ['name', 'field2']
http_login_password
string
Basic Auth password
http_login_user
string
Basic Auth login
keyed_groups
list / elements=string
Default:
[]
Add hosts to group based on the values of a variable.
leading_separator
boolean
added in 2.11 of ansible.builtin
    Choices:
  • no
  • yes ←
Use in conjunction with keyed_groups.
By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.
This is because the default prefix is "" and the default separator is "_".
Set this option to False to omit the leading underscore (or other separator) if no prefix is given.
If the group name is derived from a mapping the separator is still used to concatenate the items.
To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.
login_password
string / required
Zabbix user password.
login_user
string / required
Zabbix user name.
proxy
string
Default:
""
Proxy server to use for reaching zabbix API
server_url
string / required
URL of Zabbix server, with protocol (http or https). url is an alias for server_url.

aliases: url
strict
boolean
    Choices:
  • no ←
  • yes
If yes make invalid entries a fatal error, otherwise skip and continue.
Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.
timeout
integer
Default:
10
The timeout of API request (seconds).
use_extra_vars
boolean
added in 2.11 of ansible.builtin
    Choices:
  • no ←
  • yes
ini entries:

[inventory_plugins]
use_extra_vars = no

env:ANSIBLE_INVENTORY_USE_EXTRA_VARS
Merge extra vars into the available variables for composition (highest precedence).
validate_certs
boolean
    Choices:
  • no
  • yes ←
If set to False, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.

Examples

# Simple Inventory Plugin example
# This will create an inventory with details from zabbix such as applications name, applicaitonids, Parent Template Name, and group membership name
#It will also create 2 ansible inventory groups for enabled and disabled hosts in zabbix based on the status field.
plugin: community.zabbix.zabbix_inventory
server_url: https://zabbix.com
login_user: Admin
login_password: password
host_zapi_query:
  selectApplications: ['name', 'applicationid']
  selectParentTemplates: ['name']
  selectGroups: ['name']
validate_certs: no
groups:
  enabled: zbx_status == "0"
  disabled: zbx_status == "1"


#Using Keyed Groups
plugin: community.zabbix.zabbix_inventory
server_url: https://zabbix.com
login_user: Admin
login_password: password
validate_certs: no
keyed_groups:
  - key: zbx_status | lower
    prefix: 'env'
  - key: zbx_description | lower
    prefix: 'test'
    separator: ''

#Using proxy format of proxy is 'http://<user>:<pass>@<proxy>:<port>' or 'http://<proxy>:<port>'
plugin: community.zabbix.zabbix_inventory
server_url: https://zabbix.com
proxy: http://someproxy:8080
login_user: Admin
login_password: password
validate_certs: no

#Organize inventory groups based on zabbix host groups
plugin: community.zabbix.zabbix_inventory
server_url: https://zabbix.com
add_zabbix_groups: True
login_user: Admin
login_password: password
validate_certs: no

#Using compose to modify vars
plugin: community.zabbix.zabbix_inventory
server_url: https://zabbix.com
login_user: Admin
login_password: password
validate_certs: no
compose:
  zbx_testvar: zbx_status.replace("1", "Disabled")

Authors

  • Timothy Test (@ttestscripting)