### Installing Required Python Libraries using Requirements File Bash Source: https://github.com/zabbix/ansible-collection/blob/main/roles/host/README.md This Bash command provides an alternative way to install the required Python libraries for the role. It reads library dependencies and versions from a `requirements.txt` file located within the role's directory and installs them using pip. This method simplifies installation when the dependencies are defined in a file. ```bash python3 -m pip install -r requirements.txt ``` -------------------------------- ### Installing Required Ansible Collections (Bash) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This snippet provides the command to install the additional Ansible collections required by the Zabbix HTTP API plugin. It uses `ansible-galaxy collection install` to download and install the specified collections (`ansible.utils` and `ansible.posix`) from the Ansible Galaxy repository. This is a prerequisite step before using the HTTP API plugin. ```Bash ansible-galaxy collection install ansible.utils ansible.posix ``` -------------------------------- ### Installing Zabbix Ansible Collection Dev Version (Git, Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/README.md This command installs the latest development version of the Zabbix Ansible collection directly from its Git repository. This version is not recommended for production use but is suitable for testing and development purposes. It requires Git to be installed. ```shell ansible-galaxy collection install git+https://github.com/zabbix/ansible-collection.git ``` -------------------------------- ### Installing Required Python Libraries via requirements.txt (Bash) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This command installs all Python libraries listed in a 'requirements.txt' file, typically located within the role's directory, using pip for Python 3. This is an alternative method to install all required Python dependencies in bulk. ```bash python3 -m pip install -r requirements.txt ``` -------------------------------- ### Install Python requirements from file with pip Source: https://github.com/zabbix/ansible-collection/blob/main/roles/repository/README.md This command utilizes the Python pip package manager to install all dependencies listed in a 'requirements.txt' file located in the role directory, providing an alternative method for setting up prerequisites. ```bash python3 -m pip install -r requirements.txt ``` -------------------------------- ### Installing Molecule and Dependencies (Python/Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/molecule/default/README.md Uninstalls a potentially conflicting package (`molecule-podman`) and then installs core testing tools like `ansible-core`, `molecule`, `molecule-plugins[podman]`, `ansible-lint`, and `yamllint` using `pip`. This prepares the system for role testing with Molecule. ```Shell python3 -m pip uninstall molecule-podman python3 -m pip install ansible-core molecule molecule-plugins[podman] ansible-lint yamllint ``` -------------------------------- ### Installing Zabbix Ansible Collection (Ansible Galaxy, Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/README.md This command installs the Zabbix Ansible collection from Ansible Galaxy. It downloads the collection content, including roles, plugins, and modules, making them available for use in Ansible playbooks. This is the standard method for installing released versions of the collection. ```shell ansible-galaxy collection install zabbix.zabbix ``` -------------------------------- ### Simple Host Group Creation via HTTP API Plugin (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task shows a simplified example of creating multiple Zabbix host groups ("G1", "G2") using the `zabbix_hostgroup` module and the `httpapi` connection plugin. It illustrates that only essential parameters like `ansible_network_os`, `ansible_connection`, and basic authentication credentials (`ansible_user`, `ansible_httpapi_pass`) might be needed for a typical application, depending on the Zabbix API setup. It requires the Zabbix API endpoint to be discoverable or set via environment variables. ```YAML - name: Create host groups zabbix.zabbix.zabbix_hostgroup: state: present host_groups: - G1 - G2 vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Installing Required Ansible Collections using Bash Source: https://github.com/zabbix/ansible-collection/blob/main/roles/host/README.md This Bash command installs the necessary Ansible collections (ansible.utils, ansible.posix, and ansible.netcommon) required by the Zabbix host role. These collections provide modules and filters used by the role, such as the `ansible.utils.ipaddr` filter. This command should be run on the Ansible control node. ```bash ansible-galaxy collection install ansible.utils ansible.posix ansible.netcommon ``` -------------------------------- ### Installing Required Ansible Collections (Bash) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This command installs the necessary Ansible collections, 'ansible.utils' and 'ansible.posix', which are required dependencies for the Zabbix agent role to function correctly. These collections provide essential modules and filters. ```bash ansible-galaxy collection install ansible.utils ansible.posix ``` -------------------------------- ### Installing Required Python Libraries Individually (Bash) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This command installs specific Python libraries, 'netaddr' (version >= 0.8.0) and 'Jinja2' (version >= 3.1.2), using pip for Python 3. These libraries are dependencies for filters and templating used by the Ansible role on the control node. ```bash python3 -m pip install "netaddr>=0.8.0" "Jinja2>=3.1.2" ``` -------------------------------- ### Installing Required Python Libraries using Pip Bash Source: https://github.com/zabbix/ansible-collection/blob/main/roles/host/README.md This Bash command uses pip to install the necessary Python libraries, netaddr and Jinja2, on the Ansible control node. The `netaddr` library is a dependency for the `ansible.utils.ipaddr` filter, while Jinja2 is heavily used for templating within the role. Specific minimum versions are required. ```bash python3 -m pip install "netaddr>=0.8.0" "Jinja2>=3.1.2" ``` -------------------------------- ### Creating Zabbix Host with Max Parameters (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task uses the `zabbix_host` module to create a Zabbix host named "Example host" with a comprehensive set of configurations. It defines hostgroups, templates, status, description, tags, macros, IPMI, TLS, inventory, and multiple interface types (agent, ipmi, jmx, snmp). Connection details are provided via `ansible_network_os`, `ansible_connection`, `ansible_user`, and `ansible_httpapi_pass` variables. ```yaml - name: Create host with maximum parameters zabbix.zabbix.zabbix_host: state: present host: Example host hostgroups: - Linux servers templates: - Zabbix agent active status: enabled description: 'Host example' name: 'Example host' tags: - tag: scope value: test macros: - macro: TEST_MACRO value: example description: Description of macro example type: text ipmi_authtype: default ipmi_privilege: user ipmi_username: admin ipmi_password: your_password tls_accept: - unencrypted - psk - certificate tls_psk_identity: my_example_identity tls_psk: SET_YOUR_PSK_KEY tls_issuer: Example Issuer tls_subject: Example Subject tls_connect: psk inventory_mode: automatic inventory: type: "" # To specify an empty value serialno_b: example value hardware_full: | very very long multiple string value interfaces: - type: agent # To specify an interface with default parameters (the IP will be 127.0.0.1) - type: ipmi - type: jmx ip: 192.168.100.51 dns: test.com useip: true port: 12345 - type: snmp ip: 192.168.100.50 dns: switch.local port: 169 # To specify a non-standard value details: version: 3 bulk: true contextname: my contextname name securityname: my securityname name securitylevel: authPriv authprotocol: md5 authpassphrase: SET_YOUR_PWD privprotocol: des privpassphrase: SET_YOUR_PWD vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Install Jinja2 requirement with pip Source: https://github.com/zabbix/ansible-collection/blob/main/roles/repository/README.md This command uses the Python pip package manager to install the Jinja2 library, specifically requiring version 3.1.2 or newer, which is necessary for the Ansible role's operation. ```bash python3 -m pip install "Jinja2>=3.1.2" ``` -------------------------------- ### Creating Zabbix Proxy with Maximum Parameters (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This example shows how to create a Zabbix proxy configuring a comprehensive set of parameters, including mode, group, interfaces, TLS settings, custom timeouts, and description. Some parameters are mode-dependent. ```YAML - name: Create proxy with maximum parameters zabbix.zabbix.zabbix_proxy: state: present name: My Zabbix proxy mode: active proxy_group: My proxy group local_address: 10.10.10.10 local_port: 10051 interface: address: 127.0.0.1 port: 10051 allowed_addresses: 10.10.10.10 tls_connect: '' tls_accept: - psk - cert tls_psk_identity: my_psk tls_psk: 12345abcde... tls_issuer: my_tls_issuer tls_subject: my_tls_subject custom_timeouts: timeout_zabbix_agent: 10s timeout_simple_check: '' # To use value from Zabbix global setting timeout_snmp_agent: '{$MY_SNMP_TIMEOUT}' # To use global macro (this macro must exist in global macro) timeout_external_check: 10s timeout_db_monitor: 10s timeout_http_agent: 10s timeout_ssh_agent: 10s timeout_telnet_agent: 10s timeout_script: 10s timeout_browser: 10s description: Description of my proxy vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Filtering Zabbix Hosts by Hostgroup Wildcard (Ansible Yaml) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Demonstrates how to filter Zabbix hosts based on their linked host groups using a string with a wildcard in the `filter.hostgroups` option. This example selects hosts associated with any host group whose name starts with 'Linux'. Basic connection parameters are required. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by host group (in string format with asterisk). filter: hostgroups: 'Linux*' ``` -------------------------------- ### Creating Zabbix Proxy Group with Maximum Parameters (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This example shows how to create a Zabbix proxy group configuring all available parameters, including failover delay, minimum online proxies, and description. Supported for Zabbix versions 7.0 and above. ```YAML - name: Create proxy group with maximum parameters zabbix.zabbix.zabbix_proxy_group: state: present name: My proxy group failover_delay: '1m' min_online: '10' description: Proxy group description vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Deploying Zabbix Agent and Adding Host via API with Ansible Playbook Source: https://github.com/zabbix/ansible-collection/blob/main/roles/host/README.md Provides an example Ansible playbook combining the `zabbix.zabbix.agent` and `zabbix.zabbix.host` roles. It configures the agent for passive checks, sets firewall rules for the Zabbix server, defines Zabbix API connection details, and adds the host to Zabbix with a specified template using the host role. ```YAML - hosts: all roles: - role: zabbix.zabbix.agent ### Zabbix agent configuration agent_param_server: 256.256.256.256 # address of Zabbix server to accept connections from monitoring instance; agent_firewall_allow_from: 256.256.256.256 # address of Zabbix server to allow connections from monitoring instance using firewalld; - role: zabbix.zabbix.host ### Zabbix API properties host_zabbix_api_server: zabbix.frontend.loc # Zabbix frontend server; host_zabbix_api_port: 443 # Zabbix fronted connection port; host_zabbix_api_user: Admin # Zabbix user name for API connection; host_zabbix_api_password: zabbix # Zabbix user password for API connection; host_zabbix_api_use_ssl: True # Use secure connection; ### Zabbix host configuration host_templates: ["Linux by Zabbix agent"] # Assign list of templates to the host; ``` -------------------------------- ### Deploying Zabbix Agent 2 v6.4 for MongoDB Monitoring (Partial) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This Ansible playbook snippet configures the `zabbix.zabbix.agent` role to install Zabbix agent 2 (variant 2) version 6.4. The surrounding text indicates that this configuration is intended for MongoDB monitoring and would typically include adding the `mongodb` plugin to `agent_2_plugin_list` and potentially configuring TLS connections for MongoDB, although these specific configurations are not present in this partial code example. ```YAML - hosts: all roles: - role: zabbix.zabbix.agent agent_variant: 2 agent_major_version: 6.4 ``` -------------------------------- ### Complex Filtering and Grouping Zabbix Hosts (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Provides a complex example showcasing filtering by multiple criteria (host groups, templates, name, proxy, status, tags), querying for host groups and interfaces, composing a list of IP addresses, and performing keyed grouping based on Zabbix host group names. Requires Zabbix API credentials. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching. filter: hostgroups: ['Linux', 'Linux servers'] templates: ['*HTTP*', '*agent*'] name: ['*sql*', '*SQL*'] host: ['*sql*', '*SQL*'] proxy: ['Riga*'] status: enabled tags_behavior: 'and/or' tags: - tag: scope - tag: Location value: Riga operator: equals # Add query for host groups and interfaces. query: selectGroups: ['name'] selectInterfaces: ['ip'] # Add output. output: - name # Add postprocessing for converting 'zabbix_interfaces' to the list of interfaces and creating groups based on Zabbix host groups. compose: zabbix_ip_list: zabbix_interfaces | map(attribute='ip') keyed_groups: - key: zabbix_groups | map(attribute='name') separator: "" ``` -------------------------------- ### Deploying Zabbix Agent via HTTP Proxy in Ansible YAML Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Shows how to deploy the Zabbix agent using an HTTP proxy for environments where target machines lack direct internet access. The example uses the `agent_http_proxy` variable to specify the proxy address within the zabbix.zabbix.agent role configuration. Requires the zabbix.zabbix.agent role. ```YAML - hosts: all roles: - role: zabbix.zabbix.agent agent_param_server: 127.0.0.1 # address of Zabbix server to accept connections from; agent_param_serveractive: 127.0.0.1 # address of Zabbix server to connect using active checks; agent_param_hostmetadata: '{{ group_names | join(",") }}' # concatenate group list to the string; agent_http_proxy: http://host.containers.internal:8123 # HTTP proxy address. ``` -------------------------------- ### Clearing Zabbix Host Parameters (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task updates the existing "Example host" to clear most configurable parameters by setting them to empty strings or lists, effectively resetting the host to minimal settings while keeping it present and enabled. Host groups and status are retained. Note the accompanying important note about clearing templates/interfaces with dependencies. ```yaml - name: Clean all parameters from host zabbix.zabbix.zabbix_host: state: present host: Example host hostgroups: # Host group must not be empty - Linux servers templates: [] # Read important note in this example status: enabled description: '' name: '' # The technical name will be used tags: [] macros: [] ipmi_authtype: default ipmi_privilege: user ipmi_username: '' ipmi_password: '' tls_accept: - unencrypted tls_issuer: '' tls_subject: '' tls_connect: unencrypted proxy: '' inventory_mode: disabled interfaces: [] # Read important note in this example vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Updating Single Zabbix Proxy Parameter (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This example shows how to update only a specific parameter, like the description, for an existing Zabbix proxy. Only the proxy name and the parameter to update need to be specified. ```YAML - name: Update proxy description zabbix.zabbix.zabbix_proxy: name: My Zabbix proxy description: Description of my proxy vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Manage Zabbix Agent User Parameters with Tag (Bash) Source: https://github.com/zabbix/ansible-collection/blob/main/CHANGELOG.md This command shows how to execute an `ansible-playbook` focusing solely on managing Zabbix agent user parameters. By specifying the 'userparam' tag for the playbook (`play.yml`) and inventory (`inventory`), only the related tasks are executed. It requires Ansible installed and a compatible playbook. ```bash ansible-playbook -i inventory play.yml -t userparam ``` -------------------------------- ### Using Ansible Extra-Vars with Zabbix Inventory Plugin (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Configures the `zabbix_inventory` plugin to accept parameters like API URL, query fields, and filter tags from Ansible extra-vars. It requires setting `use_extra_vars: true` and defining variables in the inventory file using Jinja syntax (e.g., `{{ url }}`). Shows examples of passing list, dict, and string types via extra-vars. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials zabbix_api_url: 'http://{{ url }}' zabbix_user: Admin zabbix_password: zabbix use_extra_vars: true # Add additional queries query: selectMacros: '{{ macros }}' selectInventory: ['Name', 'OS', '{{ inventory_field }}'] # Filtering by tags # You can specify the tag value as a variable or the tag as a dictionary. filter: tags: - tag: OS value: '{{ os_tag_value }}' - '{{ host_tag }}' ``` -------------------------------- ### Updating Zabbix Host Status (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task updates only the `status` parameter of the "Example host" to `disabled`. By providing only the host name and the specific parameter to change, the module updates only that parameter, leaving all others untouched. ```yaml - name: Update host status zabbix.zabbix.zabbix_host: host: Example host status: disabled vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Uninstall Zabbix Agent Packages with Tag (Bash) Source: https://github.com/zabbix/ansible-collection/blob/main/CHANGELOG.md This command demonstrates using the `ansible-playbook` command to uninstall Zabbix agent packages. It specifically targets tasks tagged 'remove' within the specified playbook (`play.yml`) using the inventory file (`inventory`). It requires Ansible installed and a compatible playbook. ```bash ansible-playbook -i inventory play.yml -t remove ``` -------------------------------- ### Deploying Zabbix Agent 2 v6.4 with Ansible (Passive/Active, iptables) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This Ansible playbook snippet configures the `zabbix.zabbix.agent` role to install Zabbix agent 2 (variant 2) version 6.4, enabling both passive and active checks pointing to the specified server address. It sets host metadata from inventory groups, explicitly disables the firewalld rule while enabling the iptables rule, and limits allowed connections on the agent port. ```YAML - hosts: all roles: - role: zabbix.zabbix.agent agent_variant: 2 agent_major_version: 6.4 agent_param_server: 127.0.0.1 # address of Zabbix server to accept connections from; agent_param_serveractive: 127.0.0.1 # address of Zabbix server to connect using active checks; agent_param_hostmetadata: '{{ group_names | join(",") }}' # concatenate group list to the string; agent_apply_firewalld_rule: false # "auto" is the default and recommended value; agent_apply_iptables_rule: true # "auto" is the default value; agent_firewall_allow_from: 127.0.0.1 # limit listening on agent port only from the defined source address ``` -------------------------------- ### Downgrading Zabbix Agent Version via Ansible Playbook YAML Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Demonstrates how to downgrade the Zabbix agent to a specific major version using the zabbix.zabbix.agent role in Ansible. It highlights the need to remove the previously installed newer version (`agent_remove_previous_packages: true`) and specifies the target version (`agent_major_version: "6.0"`). Requires the zabbix.zabbix.agent role. ```YAML - hosts: all roles: - role: zabbix.zabbix.agent agent_major_version: "6.0" agent_remove_previous_packages: true # removes previously installed package of Zabbix agent (according to current settings); agent_param_server: 127.0.0.1 # address of Zabbix server to accept connections from; agent_param_serveractive: 127.0.0.1 # address of Zabbix server to connect using active checks; agent_param_hostmetadata: '{{ group_names | join(",") }}' # concatenate group list to the string; ``` -------------------------------- ### Listing Available Ansible Cache Plugins (Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This command utilizes the `ansible-doc` utility to list all available cache plugins that can be used by Ansible. It is provided as a reference for the `cache_plugin` parameter configuration. ```Shell ansible-doc -t cache -l ``` -------------------------------- ### Creating Zabbix Proxy with Minimum Parameters (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task demonstrates how to create a Zabbix proxy with only the required parameters: state and name. It assumes the necessary Zabbix API connection variables are defined. ```YAML - name: Create proxy zabbix.zabbix.zabbix_proxy: state: present name: My Zabbix proxy vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Creating Host Groups using HTTP API Plugin (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task demonstrates creating Zabbix host groups ("Group 1") using the `zabbix_hostgroup` module configured to use the `httpapi` connection plugin. It showcases setting various connection parameters (host, port, SSL, validation, path) and authentication methods (username/password, API token, basic HTTP auth) within the task's `vars` block. It requires specifying `ansible_connection`, `ansible_network_os`, and connection details like `ansible_host` or `zabbix_api_url`. ```YAML - name: Create host groups zabbix.zabbix.zabbix_hostgroup: state: present host_groups: - Group 1 vars: # Connection parameters ansible_host: zabbix-api.com # Specify Zabbix API address. ansible_connection: httpapi # Specify HTTP API plugin. ansible_network_os: zabbix.zabbix.zabbix # Specify which HTTP API plugin to use. ansible_httpapi_port: 80 # Specify the port for connecting to Zabbix API. ansible_httpapi_use_ssl: False # Specify the type of connection. True for https, False for http (by default). ansible_httpapi_validate_certs: False # Specify certificate validation. # User parameters for connecting to Zabbix API ansible_user: Admin # Username to connect to Zabbix API. ansible_httpapi_pass: zabbix # Password to connect to Zabbix API. # Token for connecting to Zabbix API zabbix_api_token: your_secret_token # Specify your token to connect to Zabbix API. # Path to connect to Zabbix API zabbix_api_url: '/zabbix' # The field is empty by default. You can specify your connection path (e.g., '/zabbix'). # User parameters for basic HTTP authorization # These options only affect the basic HTTP authorization configured on the web server. http_login: my_http_login # Username for connecting to API in case of additional basic HTTP authorization. http_password: my_http_password # Password for connecting to API in case of additional basic HTTP authorization. ``` -------------------------------- ### Running Ansible Playbook Directly (Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/molecule/default/README.md Executes the `converge.yml` playbook using the specified `inventory` file. It limits the run to hosts tagged with `ubuntu` and includes tasks tagged `all`, `verify`, and `report`. This is a manual test execution step outside of Molecule. ```Shell ansible-playbook -i inventory converge.yml -l ubuntu -t all,verify,report ``` -------------------------------- ### Configuring Zabbix Inventory Caching (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Explains how to enable caching for the `zabbix_inventory` plugin by setting `cache: yes`. It also shows how to configure the cache plugin (`jsonfile`), the cache timeout, and the cache connection path. Caching helps improve performance by avoiding repeated API calls if input parameters haven't changed. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by host group. filter: hostgroups: 'Linux*' # Add caching options. cache: yes cache_plugin: jsonfile cache_timeout: 7200 cache_connection: /tmp/zabbix_inventory ``` -------------------------------- ### Defining PG Plugin Ansible-Managed Session Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for configuring a PostgreSQL plugin session when certificate files are managed by Ansible. The `source_` prefixes indicate paths to certificate files on the Ansible execution environment. Includes fields for connection details, source TLS certificate file paths, and cache mode. ```YAML { name: "", uri: "", user: "", password: "", database: "", tlsconnect: "", source_tlscafile: "", source_tlscertfile: "", source_tlskeyfile: "", cahcemode: ""} ``` -------------------------------- ### Creating Zabbix Host with Ansible Module (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task snippet demonstrates how to use the `zabbix_host` module from the Zabbix collection to create a new host. It sets the host state to 'present', defines the host name, and assigns it to a hostgroup. Required Ansible variables for connecting to the Zabbix API via httpapi are also included. ```yaml - name: Create host zabbix.zabbix.zabbix_host: state: present host: Example host hostgroups: - Linux servers vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Defining MySQL Plugin Ansible-Managed Session Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for configuring a MySQL plugin session when certificate files are managed by Ansible. The `source_` prefixes indicate paths to certificate files on the Ansible execution environment. Includes fields for connection details and source TLS certificate file paths. ```YAML { name: "", uri: "", user: "", password: "", tlsconnect: "", source_tlscafile: "", source_tlscertfile: "", source_tlskeyfile: ""} ``` -------------------------------- ### Running Molecule Test on All Scenarios (Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/molecule/default/README.md Executes the full Molecule testing lifecycle (create, converge, verify, destroy, etc.) for every scenario defined in the `molecule` directory. This is a comprehensive command to test the role against all configured environments. ```Shell molecule test --all ``` -------------------------------- ### Creating Zabbix Proxy Group with Minimum Parameters (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task demonstrates how to create a Zabbix proxy group with only the required parameters: state and name. Supported for Zabbix versions 7.0 and above. ```YAML - name: Create proxy group zabbix.zabbix.zabbix_proxy_group: state: present name: My proxy group vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Running Molecule with RHEL 8 Platform Config (Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/molecule/default/README.md Executes a Molecule action (create, converge, or test) using the configuration specified in `.config/molecule/config.rhel.8.yml`. This is for testing the role specifically on a RHEL 8-based platform, noting a potential requirement for older Ansible versions as mentioned in the text. ```Shell molecule -c ".config/molecule/config.rhel.8.yml" create #/converge/test ``` -------------------------------- ### Creating Multiple Host Groups (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md This Ansible task demonstrates how to create multiple Zabbix host groups ("G1", "G2") using the `zabbix_hostgroup` module. It sets the `state` to `present` and provides a list of group names in the `hostgroups` parameter. Essential connection parameters (`ansible_network_os`, `ansible_connection`, `ansible_user`, `ansible_httpapi_pass`) are provided in the `vars` block, assuming the Zabbix API endpoint is configured elsewhere. ```YAML - name: Create host groups zabbix.zabbix.zabbix_hostgroup: state: present hostgroups: - G1 - G2 vars: ansible_network_os: zabbix.zabbix.zabbix ansible_connection: httpapi ansible_user: Admin ansible_httpapi_pass: zabbix ``` -------------------------------- ### Configuring Zabbix Inventory Plugin for Grouping by Host Group and Status (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Demonstrates how to use the `zabbix_inventory` plugin to filter hosts by group, fetch host group and status data, transform digit status (0/1) to verbose (Enabled/Disabled) using `compose`, and group hosts using both standard `groups` (by status) and `keyed_groups` (by host group name). Requires Zabbix API URL, user, and password. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by host group. filter: hostgroups: 'Linux*' # Add query for selecting host groups from hosts. This parameter will be used for grouping. query: selectGroups: ['name'] # Compose for transformation from digit status (0, 1) to verbose (Enabled, Disabled). compose: zabbix_verbose_status: zabbix_status.replace("1", "Disabled").replace("0", "Enabled") # Grouping by status. # If status is '0', host will be added to group 'enabled'. # If status is '1', host will be added to group 'disabled'. groups: enabled: zabbix_status == "0" disabled: zabbix_status == "1" # Grouping with keyed_group. # Jinja pattern will be used as a key for grouping. As a result, we will have the same groups as in Zabbix. keyed_groups: - key: zabbix_groups | map(attribute='name') separator: "" ``` -------------------------------- ### Configuring Minimum Zabbix API Connection (Ansible Yaml) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Provides the minimum required configuration for the Ansible Zabbix Inventory plugin to connect to a Zabbix API endpoint. It specifies the plugin name, the API URL, and credentials (username and password). Be aware that this configuration retrieves all hosts, which can strain the Zabbix server. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix ``` -------------------------------- ### Defining PG Plugin Self-Managed Session Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for configuring a PostgreSQL plugin session when certificate files are managed manually on the target machine. Requires the `tlsconnect` key for encryption to make certificate files mandatory. Includes fields for connection details, TLS certificate file paths (final paths on the target), and cache mode. ```YAML { name: "", uri: "", user: "", password: "", database: "", tlsconnect: "", tlscafile: "", tlscertfile: "", tlskeyfile: "", cachemode: ""} ``` -------------------------------- ### Defining PG Plugin Ansible-Managed Default Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for the default PostgreSQL plugin connection settings when certificate files are managed by Ansible. The `source_` prefixes indicate paths to certificate files on the Ansible execution environment. Includes fields for default connection details, source TLS certificate file paths, and cache mode, but does not include the `name` field used for specific sessions. ```YAML { uri: "", user: "", password: "", database: "", tlsconnect: "", source_tlscafile: "", source_tlscertfile: "", source_tlskeyfile: "", cachemode: ""} ``` -------------------------------- ### Running Molecule with Debian Platform Config (Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/molecule/default/README.md Executes a Molecule action (create, converge, or test - indicated by the comment) using the configuration specified in `.config/molecule/config.debian.yml`. This allows testing the role specifically on a Debian-based platform as defined in the custom config file. ```Shell molecule -c ".config/molecule/config.debian.yml" create #/converge/test ``` -------------------------------- ### Defining MSSQL Plugin Ansible-Managed Session Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for configuring an MSSQL plugin session when certificate files are managed by Ansible. The `source_` prefix indicates the path to the CA certificate file on the Ansible execution environment. Includes fields for connection details, source CA certificate path, and various TLS/encryption options. ```YAML { name: "", uri: "", user: "", password: "", source_cacertpath: "", trustservercertificate: "", hostnameincertificate: "", encrypt: "", tlsminversion: ""} ``` -------------------------------- ### Defining MySQL Plugin Ansible-Managed Default Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for the default MySQL plugin connection settings when certificate files are managed by Ansible. The `source_` prefixes indicate paths to certificate files on the Ansible execution environment. Includes fields for default connection details and source TLS certificate file paths, but does not include the `name` field used for specific sessions. ```YAML { uri: "", user: "", password: "", tlsconnect: "", source_tlscafile: "", source_tlscertfile: "", source_tlskeyfile: ""} ``` -------------------------------- ### Grouping Zabbix Hosts by Tag Name (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Shows how to use the `zabbix_inventory` plugin to filter hosts that have a specific tag (`Location` in this case) and then group these hosts based on the *name* of the tag (which will be the same, `Location`, for all grouped hosts in this specific keyed_group configuration) using `keyed_groups` and fetching tags with `selectTags: 'extend'`. Requires Zabbix API credentials. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by tag name. filter: tags: - tag: Location # Add query for selecting tags from hosts. This parameter will be used for grouping. query: selectTags: 'extend' # Grouping with keyed_group. # Jinja pattern will be used as a key for grouping. As a result, we will have groups corresponding to the tag name in Zabbix. keyed_groups: - key: zabbix_tags | map(attribute='tag') separator: "" ``` -------------------------------- ### Running Molecule with RHEL 9 Platform Config (Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/molecule/default/README.md Executes a Molecule action (create, converge, or test) using the configuration specified in `.config/molecule/config.rhel.9.yml`. This targets testing the role specifically on a RHEL 9-based platform using its defined settings from the custom config file. ```Shell molecule -c ".config/molecule/config.rhel.9.yml" create #/converge/test ``` -------------------------------- ### Defining MySQL Plugin Self-Managed Session Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for configuring a MySQL plugin session when certificate files are managed manually on the target machine. Requires the `tlsconnect` key for encryption to make certificate files mandatory. Includes fields for connection details and TLS certificate file paths (final paths on the target). ```YAML { name: "", uri: "", user: "", password: "", tlsconnect: "", tlscafile: "", tlscertfile: "", tlskeyfile: ""} ``` -------------------------------- ### Composing Zabbix Host IP List from Interfaces (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Illustrates configuring the `zabbix_inventory` plugin to filter hosts by group, query their interface data (`selectInterfaces`), and transform the list of interface objects into a simple list of IP addresses using the `compose` parameter and a Jinja filter (`map(attribute='ip')`). Requires Zabbix API credentials. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by host group. filter: hostgroups: 'Linux*' # Add query for selecting interfaces from hosts. This parameter will be used for composing. query: selectInterfaces: ['ip'] # Add 'compose' for transforming Zabbix interfaces to the list of IP addresses. compose: zabbix_ip_list: zabbix_interfaces | map(attribute='ip') ``` -------------------------------- ### Filtering Zabbix Hosts by Multiple Hostgroups List (Ansible Yaml) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Shows how to select hosts linked to any of several specified host groups by providing a list of group names (including potential wildcards) to the `filter.hostgroups` option. This allows for flexible inclusion criteria based on multiple groups. Basic connection parameters are needed. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by host group (in list format). filter: hostgroups: - Linux - Linux Ubuntu - 'Windows*' ``` -------------------------------- ### Deploying Zabbix Agentd Active Checks with Ansible Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This Ansible playbook snippet uses the `zabbix.zabbix.agent` role to deploy Zabbix agentd configured only for active checks (`agent_param_startagents: 0`). It connects to the Zabbix server specified by `agent_param_serveractive` and uses a comma-separated list of inventory group names (`group_names | join(',')`) as the host metadata for autoregistration. ```YAML - hosts: all roles: - role: zabbix.zabbix.agent agent_param_serveractive: 127.0.0.1 # address of Zabbix server to connect using active checks; agent_param_startagents: 0 # do not spawn passive check processes that listen for connections; agent_param_hostmetadata: '{{ group_names | join(",") }}' # concatenate group list to the string; ``` -------------------------------- ### Running Molecule Test on Specific Scenarios (Shell) Source: https://github.com/zabbix/ansible-collection/blob/main/molecule/default/README.md Executes the full Molecule testing lifecycle for the explicitly listed scenarios: `agent2`, `agent2_cert`, and `agent2_psk`. This command allows for focused testing of particular configurations or environments without running all tests. ```Shell molecule test -s agent2 -s agent2_cert -s agent2_psk ``` -------------------------------- ### Defining MSSQL Plugin Ansible-Managed Default Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for the default MSSQL plugin connection settings when certificate files are managed by Ansible. The `source_` prefix indicates the path to the CA certificate file on the Ansible execution environment. Includes fields for default connection details, source CA certificate path, and various TLS/encryption options, but does not include the `name` field used for specific sessions. ```YAML { uri: "", user: "", password: "", source_cacertpath: "", trustservercertificate: "", hostnameincertificate: "", encrypt: "", tlsminversion: ""} ``` -------------------------------- ### Executing Ansible Playbook with Restart Tag Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This shell command demonstrates how to execute an Ansible playbook (`play.yml`) using a specific inventory (`inventory`) and applying the `restart` tag. This tag triggers handlers (like service restarts) even if no configuration changes were made by tasks without this tag. ```Ansible ansible-playbook -i inventory play.yml -t all,restart ``` -------------------------------- ### Defining MSSQL Plugin Self-Managed Session Skeleton (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md Defines the structure for configuring an MSSQL plugin session when certificate files are managed manually on the target machine. Includes fields for connection details, CA certificate path (final path on the target), and various TLS/encryption options like trustServerCertificate, hostnameInCertificate, encrypt, and tlsMinVersion. ```YAML { name: "", uri: "", user: "", password: "", cacertpath: "", trustservercertificate: "", hostnameincertificate: "", encrypt: "", tlsminversion: ""} ``` -------------------------------- ### Filtering Zabbix Hosts by Multiple Criteria (Ansible Yaml) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Demonstrates the use of multiple filtering criteria simultaneously within the `filter` section, such as host groups, linked templates (using wildcards), and host visible names (using wildcards). This allows for complex queries to pinpoint specific sets of hosts in Zabbix. Basic connection parameters are required. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by host group, template, and visible name at the same time. filter: hostgroups: Linux templates: ['*HTTP*', '*agent*'] name: ['*sql*', '*SQL*'] ``` -------------------------------- ### Composing Zabbix Host Group Name List (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Shows how to configure the `zabbix_inventory` plugin to filter hosts by a specific group and fetch the associated host group data (`selectGroups`). The `compose` parameter is then used with a Jinja filter (`map(attribute='name')`) to create a list containing the names of the host groups the host belongs to. Requires Zabbix API credentials. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching by host group. filter: hostgroups: 'Linux*' # Add query for selecting host groups from hosts. This parameter will be used for composing. query: selectGroups: ['name'] # Add 'compose' for transforming Zabbix host groups to the list of host groups. compose: zabbix_groups_list: zabbix_groups | map(attribute='name') ``` -------------------------------- ### Deploying Zabbix Agentd with PSK Encryption using Ansible Source: https://github.com/zabbix/ansible-collection/blob/main/roles/agent/README.md This Ansible playbook snippet configures Zabbix agentd deployment using the `zabbix.zabbix.agent` role with PSK encryption enabled for both passive (`agent_param_tlsaccept: [psk]`) and active (`agent_param_tlsconnect: psk`) connections. It specifies the source path for the PSK file (`agent_source_tlspskfile`) which will be transferred and used, and sets the PSK identity (`agent_param_tlspskidentity`) required for Zabbix autoregistration. ```YAML - hosts: all roles: - role: zabbix.zabbix.agent agent_param_server: 127.0.0.1 # address of Zabbix server to accept connections from; agent_param_serveractive: 127.0.0.1 # address of Zabbix server to connect using active checks; agent_param_hostmetadata: '{{ group_names | join(",") }}' # concatenate group list to the string; agent_param_tlsconnect: psk agent_param_tlsaccept: [psk] agent_source_tlspskfile: TEST/autoregistration.psk # "autoregistration" key will be placed to TEST folder; agent_param_tlspskidentity: 'PSK_ID_AUTOREGISTRATION' # length <= 128 char ``` -------------------------------- ### Grouping Zabbix Hosts by Composed Status and Filtering by Empty Tag Value (YAML) Source: https://github.com/zabbix/ansible-collection/blob/main/plugins/README.md Shows filtering hosts by a tag with an empty value (`Location: ''`), querying tag data, composing a verbose status string from the digit status (0/1), and then using the composed verbose status (`zabbix_verbose_status`) for keyed grouping. Requires Zabbix API credentials. ```yaml --- plugin: "zabbix.zabbix.zabbix_inventory" # Set credentials. zabbix_api_url: http://your-zabbix.com zabbix_user: Admin zabbix_password: zabbix # Add condition for searching. filter: tags: - tag: Location value: '' operator: equals # Add query for tags. query: selectTags: 'extend' # Add output. output: - name # Add postprocessing. keyed_groups: - key: zabbix_verbose_status separator: "" compose: zabbix_verbose_status: zabbix_status.replace("1", "Disabled").replace("0", "Enabled") ```