### Install Zabbix Agent2 with Plugins Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_AGENT_ROLE.md Example of how to install Zabbix Agent2 along with specific plugins for Debian/Ubuntu systems. Ensure the versioning matches your requirements. ```yaml zabbix_agent_packages: - zabbix-agent2 - zabbix-agent2-plugin-mongodb ``` -------------------------------- ### Install Zabbix Agent2 with Plugins (RedHat) Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_AGENT_ROLE.md Example for installing Zabbix Agent2 and plugins on RedHat-based systems, including version suffixes for consistency. The version variables `zabbix_agent_version` and `zabbix_agent_version_minor` should be defined. ```yaml zabbix_agent_packages: - "zabbix-agent2-{{ zabbix_agent_version }}.{{ zabbix_agent_version_minor }}" - "zabbix-agent2-plugin-mongodb-{{ zabbix_agent_version }}.{{ zabbix_agent_version_minor }}" ``` -------------------------------- ### Example Playbook Usage Source: https://github.com/ansible-collections/community.zabbix/blob/main/CONTRIBUTING.md An example of how to use community.zabbix roles and modules within an Ansible playbook. ```yaml - hosts: myserver roles: - role: community.zabbix.zabbix_agent zabbix_agent_server: 10.0.0.1 ... tasks: - name: Configure Zabbix host community.zabbix.zabbix_host: server_url: http://10.0.0.1/ ... delegate_to: localhost ``` -------------------------------- ### Install Zabbix Web in a Multi-Host Setup Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_WEB_ROLE.md Configure Zabbix Web on a dedicated host, separate from the Zabbix Server. This setup requires specifying the Zabbix server's hostname. ```yaml - hosts: zabbix-server become: yes roles: - role: community.zabbix.zabbix_server zabbix_server_database: mysql zabbix_db_type_long: mysql zabbix_server_dbport: 3306 - hosts: zabbix-web become: yes roles: - role: geerlingguy.apache - role: geerlingguy.php - role: community.zabbix.zabbix_web zabbix_api_server_url: zabbix.mydomain.com zabbix_server_hostname: zabbix-server zabbix_server_database: mysql zabbix_db_type_long: mysql zabbix_server_dbport: 3306 ``` -------------------------------- ### Install Zabbix Server and Web Role Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_web/README.md Installs both the Zabbix Server and Zabbix Web roles when they are on the same host. ```bash ansible-galaxy install community.zabbix.zabbix_server ``` -------------------------------- ### Configure Zabbix Proxy with PostgreSQL (Local Setup) Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_PROXY_ROLE.md Set these variables for a local PostgreSQL setup. The role will create the database and user. ```yaml zabbix_proxy_database: pgsql zabbix_proxy_dbport: 5432 zabbix_proxy_dbpassword: ``` -------------------------------- ### Zabbix Agent2 Configuration Example Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_agent/README.md Example configuration entry for zabbix_agent2.conf to control remote command logging. ```ini Plugins.SystemRun.LogRemoteCommands=0 ``` -------------------------------- ### Install Zabbix Web on a Single Instance Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_WEB_ROLE.md Deploy Zabbix Web on a host that also runs Zabbix Server and MySQL. Ensure Apache and PHP are installed. ```yaml - hosts: zabbix-server become: yes roles: - role: geerlingguy.apache - role: geerlingguy.php - role: community.zabbix.zabbix_server zabbix_server_database: mysql zabbix_db_type_long: mysql zabbix_server_dbport: 3306 - role: community.zabbix.zabbix_web zabbix_api_server_url: zabbix.mydomain.com zabbix_server_database: mysql zabbix_db_type_long: mysql zabbix_server_dbport: 3306 ``` -------------------------------- ### Zabbix Server PostgreSQL Local Setup Variables Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_server/README.md Configure these variables for a local PostgreSQL setup. The role will create the database and user. ```yaml zabbix_server_database: pgsql zabbix_server_database_long: postgresql zabbix_server_dbport: 5432 zabbix_server_dbpassword: ``` -------------------------------- ### Install community.zabbix.zabbix_manage_repo Role Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_REPO_ROLE.md Use this command to install the Ansible role for managing Zabbix repositories. ```bash ansible-galaxy install community.zabbix.zabbix_manage_repo ``` -------------------------------- ### Configure Zabbix Proxy with PostgreSQL (Separate Setup) Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_PROXY_ROLE.md Set these variables for a PostgreSQL setup on a separate host. Ensure the privileged user has permissions to create databases and users. ```yaml zabbix_proxy_database: pgsql zabbix_proxy_dbport: 5432 zabbix_proxy_dbhost: pgsql-host zabbix_proxy_dbhost_run_install: false zabbix_proxy_dbpassword: zabbix_proxy_privileged_host: '%' zabbix_proxy_pgsql_login_host: pgsql-host zabbix_proxy_pgsql_login_user: postgres zabbix_proxy_pgsql_login_password: changeme zabbix_proxy_pgsql_login_port: 5432 ``` -------------------------------- ### Install ansible.netcommon Collection Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_PROXY_ROLE.md Install the ansible.netcommon collection if you intend to create Zabbix proxies via the API as part of the role's execution. ```bash ansible-galaxy collection install ansible.netcommon ``` -------------------------------- ### Install Molecule Requirements Source: https://github.com/ansible-collections/community.zabbix/blob/main/CONTRIBUTING.md Install the Python dependencies required for Molecule testing using pip. ```bash (ansible-2.18.x-venv) ... $ pip install -r molecule/requirements.txt ``` -------------------------------- ### Install and Configure Zabbix Web Service Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_WEB_SERVICE_ROLE.md This playbook installs and configures the Zabbix Web Service using the community.zabbix.zabbix_web_service role. It demonstrates setting essential configuration variables like allowed IPs and optional API settings for frontend URL configuration. ```yaml - name: Install and configure Zabbix Web Service hosts: zabbix_web_service become: true vars: zabbix_web_service_allowedip: "127.0.0.1,192.168.1.0/24" # Optional: Automatically set the Frontend URL in Zabbix Server settings zabbix_api_frontend_url: true zabbix_frontend_url: "https://zabbix.example.com/zabbix" zabbix_api_server_host: "127.0.0.1" zabbix_api_login_user: "Admin" zabbix_api_login_pass: "zabbix" roles: - role: community.zabbix.zabbix_web_service ``` -------------------------------- ### Install Zabbix Agent2 with Plugins Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_agent/README.md Specify Zabbix Agent2 and its plugins for installation. Ensure version suffixes are included for RedHat-based systems to match the agent package version. ```yaml zabbix_agent_packages: - zabbix-agent2 - zabbix-agent2-plugin-mongodb ``` ```yaml zabbix_agent_packages: - "zabbix-agent2-{{ zabbix_agent_version }}.{{ zabbix_agent_version_minor }}" - "zabbix-agent2-plugin-mongodb-{{ zabbix_agent_version }}.{{ zabbix_agent_version_minor }}" ``` -------------------------------- ### Example UserParameter Template for MySQL Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_AGENT_ROLE.md This is an example Jinja2 template file for a custom user parameter. It defines how to check MySQL status using `mysqladmin`. ```jinja2 UserParameter=mysql.ping_to,mysqladmin -uroot ping | grep -c alive ``` -------------------------------- ### Example UserParameter Jinja2 Template Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_agent/README.md This is an example of a Jinja2 template file for a custom user parameter. It defines a UserParameter directive that can be used by the Zabbix agent. ```jinja2 UserParameter=mysql.ping_to,mysqladmin -uroot ping | grep -c alive ``` -------------------------------- ### Install Windows Collections for Ansible Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_agent/README.md Install the 'ansible.windows' and 'community.windows' collections for managing Windows systems with Ansible 2.10 or newer. These collections contain the 'win_' modules. ```sh ansible-galaxy collection install ansible.windows ansible-galaxy collection install community.windows ``` -------------------------------- ### Use Zabbix Collection Role for Agent Installation Source: https://github.com/ansible-collections/community.zabbix/blob/main/README.md Example of using the community.zabbix.zabbix_agent role in an Ansible playbook. Specify the Zabbix server address using the zabbix_agent_server variable. ```yaml --- - name: Using Zabbix collection to install Zabbix Agent hosts: localhost roles: - role: community.zabbix.zabbix_agent zabbix_agent_server: zabbix.example.com ... ``` -------------------------------- ### Install External Collections Source: https://github.com/ansible-collections/community.zabbix/blob/main/README.md Install required external Ansible collections using ansible-galaxy. Ensure these are installed before proceeding with the community.zabbix collection. ```bash ansible-galaxy collection install ansible.posix ansible-galaxy collection install community.general ansible-galaxy collection install ansible.netcommon ``` -------------------------------- ### Install Required Ansible Collections Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_WEB_ROLE.md Install the necessary Ansible collections required for modules like seboolean. Ensure these are installed before using the role. ```bash ansible-galaxy collection install ansible.posix ansible-galaxy collection install community.general ``` -------------------------------- ### Zabbix Server PostgreSQL Separate Setup Variables Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_server/README.md Configure these variables for a PostgreSQL instance on a separate host. Ensure the provided credentials have database creation privileges. ```yaml zabbix_server_database: pgsql; zabbix_server_database_long: postgresql zabbix_server_dbport: 5432 zabbix_server_dbhost: pgsql-host zabbix_server_dbhost_run_install: false zabbix_server_dbpassword: zabbix_server_privileged_host: '%' zabbix_server_pgsql_login_host: pgsql-host zabbix_server_pgsql_login_user: postgres zabbix_server_pgsql_login_password: changeme zabbix_server_pgsql_login_port: 5432 ``` -------------------------------- ### Install Zabbix Web Role Source: https://github.com/ansible-collections/community.zabbix/blob/main/roles/zabbix_web/README.md Installs the Zabbix Web Ansible role using ansible-galaxy. ```bash ansible-galaxy install community.zabbix.zabbix_web ``` -------------------------------- ### Example Playbook for Zabbix Server and Java Gateway Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_JAVAGATEWAY_ROLE.md Demonstrates how to include and configure the community.zabbix.zabbix_server and community.zabbix.zabbix_javagateway roles in an Ansible playbook. Variables can be passed to customize the role's behavior. ```yaml - hosts: zabbix-server sudo: yes roles: - role: community.zabbix.zabbix_server zabbix_server_javagateway: 192.168.1.2 - role: community.zabbix.zabbix_javagateway ``` -------------------------------- ### Apply sysctl Configuration Source: https://github.com/ansible-collections/community.zabbix/blob/main/CONTRIBUTING.md Apply the inotify configuration changes without requiring a reboot. ```bash sudo sysctl -p /etc/sysctl.d/inotify.conf ``` -------------------------------- ### Install Docker Compose for Module Testing Source: https://github.com/ansible-collections/community.zabbix/blob/main/CONTRIBUTING.md Install docker-compose, a dependency for running Ansible module integration tests locally. ```bash pip install docker-compose ``` -------------------------------- ### Install ansible.posix Collection Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_PROXY_ROLE.md Install the ansible.posix collection, which is required for modules like seboolean when using Ansible 2.10 and higher. ```bash ansible-galaxy collection install ansible.posix ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/ansible-collections/community.zabbix/blob/main/CONTRIBUTING.md Create a new Python virtual environment for isolating dependencies and activate it. ```bash python3 -m venv ansible-2.18.x-venv source ansible-2.18.x-venv/bin/activate ``` -------------------------------- ### Manage Zabbix Host with Authentication Key Source: https://github.com/ansible-collections/community.zabbix/blob/main/README.md Example of managing Zabbix server elements using the community.zabbix.zabbix_host module with an authentication key. Configure network OS, connection details, and the Zabbix authentication key. ```yaml - name: Using Zabbix collection to manage Zabbix Server's elements with authentication key hosts: zabbix.example.net vars: ansible_network_os: community.zabbix.zabbix ansible_connection: httpapi ansible_httpapi_port: 80 ansible_httpapi_use_ssl: false # Set to true for HTTPS ansible_httpapi_validate_certs: false # For HTTPS et to true to validate server's certificate ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895 tasks: - name: Ensure host is monitored by Zabbix community.zabbix.zabbix_host: ... ``` -------------------------------- ### Install community.postgresql Collection Source: https://github.com/ansible-collections/community.zabbix/blob/main/docs/ZABBIX_PROXY_ROLE.md Install the community.postgresql collection for PostgreSQL users on Ansible 2.10 or newer, as postgresql_ modules are now part of collections. ```bash ansible-galaxy collection install community.postgresql ``` -------------------------------- ### Use Zabbix Host Module with Collection Included Source: https://github.com/ansible-collections/community.zabbix/blob/main/README.md Example of using the zabbix_host module after including the community.zabbix collection in the playbook. This demonstrates simplified module referencing. ```yaml - name: Using Zabbix collection to manage Zabbix Server's elements with username/password hosts: zabbix.example.com vars: ansible_network_os: community.zabbix.zabbix ansible_connection: httpapi ansible_httpapi_port: 80 ansible_httpapi_use_ssl: false # Set to true for HTTPS ansible_httpapi_validate_certs: false # For HTTPS et to true to validate server's certificate ansible_user: Admin ansible_httpapi_pass: zabbix tasks: - name: Ensure host is monitored by Zabbix zabbix.zabbix_host: ... ```