Write a ansible playbook that contain the installation and configuration of zabbix-proxy machine on alma9. The proxy should connect to the server instance under inst01.domain.internal. Use PSK encryption for proxy-server-com. Use latest versionof the official zabbix collection on galaxy. Also using a mariaDB mysql db with a proper and secure setup.
This whole approach must be highly professional and proper planned
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is a highly professional and properly planned Ansible playbook for installing and configuring a Zabbix proxy on Alma 9. This playbook follows best practices for security, idempotency, modularity, and error handling. It uses the official Zabbix collection from Ansible Galaxy (specifically, the zabbix.zabbix collection, assuming the latest version is installed via ansible-galaxy collection install zabbix.zabbix).
Key Planning Decisions:
Idempotency: All tasks are designed to be idempotent using Ansible's state management (e.g., state: present for packages and services).
Security:
Use Ansible Vault for sensitive variables like database passwords and PSK keys to avoid exposing them in plain text.
Secure MariaDB setup includes setting a root password, creating a dedicated database and user, and granting minimal privileges.
PSK encryption is implemented by generating a secure PSK key using OpenSSL and configuring it in the Zabbix proxy.
Modularity: The playbook is structured with separate sections for MariaDB setup, Zabbix repository addition, Zabbix proxy installation, and configuration. It uses a Jinja2 template for the Zabbix proxy configuration file.
Error Handling: Tasks include ignore_errors where appropriate, and handlers are used for service restarts to ensure changes are applied atomically.
Variables: Sensitive variables are defined in a separate vars file (e.g., vars/main.yml) and encrypted with Ansible Vault. Non-sensitive variables are also defined there for easy management.
Collections: The playbook requires the zabbix.zabbix collection. Run ansible-galaxy collection install zabbix.zabbix before executing the playbook to ensure the latest version is used.
Assumptions:
The target host is Alma 9 and is defined in your Ansible inventory (e.g., under a group like zabbix_proxy_hosts).
You have already set up the Zabbix server at inst01.domain.internal and ensured it is reachable.
MariaDB will be installed and configured on the same host as the Zabbix proxy for simplicity, but in a production environment, consider separating them.
The playbook runs with elevated privileges (become: yes).
Testing and Validation: Before running in production, test the playbook in a staging environment. Use --check mode in Ansible to simulate changes.
Dependencies:
Ansible 2.9+ with the zabbix.zabbix collection installed.
OpenSSL must be available on the target host for PSK generation.
Files Structure:
playbook.yml: The main playbook file.
templates/zabbix_proxy.conf.j2: A Jinja2 template for the Zabbix proxy configuration.
vars/main.yml: A variables file (encrypt with Ansible Vault for secrets).
Step-by-Step Playbook Explanation:
MariaDB Setup: Install MariaDB, secure it, create a database and user for Zabbix proxy, and ensure proper permissions.
Zabbix Repository and Installation: Add the Zabbix repository and install the Zabbix proxy package using the collection where possible.
PSK Generation and Configuration: Generate a PSK key securely and configure the Zabbix proxy to use it for encrypted communication.
Zabbix Proxy Configuration: Use a template to configure the proxy with the server details, database connection, and PSK.
Service Management: Start and enable services, with handlers for restarts.
The Ansible Playbook
yaml
vars/main.yml (Example)
Store this in a separate file and encrypt sensitive values with Ansible Vault (e.g., ansible-vault encrypt vars/main.yml).
yaml
---
# Non-sensitive variables
zabbix_version: "6.0" # Adjust to the latest version as needed
zabbix_db_name: "zabbix_proxy"
zabbix_db_user: "zabbix_proxy_user"
zabbix_server: "inst01.domain.internal"
zabbix_psk_identity: "ZabbixProxyPSK" # PSK identity for the proxy
# Sensitive variables - Encrypt with Ansible Vault
mysql_root_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
... (encrypted content) ...
zabbix_db_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
... (encrypted content) ...
Run the playbook: ansible-playbook playbook.yml --ask-vault-pass --tags zabbix,mariadb (use tags as needed).
Verify: After execution, check Zabbix proxy logs (/var/log/zabbix/zabbix_proxy.log) and ensure connectivity to the server.
This playbook is designed for maintainability, security, and scalability. If you need further customization (e.g., integrating more from the Zabbix collection), let me know!
Dataset releases
Not yet included in a published release.
---
- name: Install and Configure Zabbix Proxy on Alma 9
hosts: zabbix_proxy_hosts # Define this in your inventory file
become: yes # Run tasks with elevated privileges
gather_facts: yes # Gather host facts for conditional logic
vars_files:
- vars/main.yml # External vars file for better organization
tasks:
# Section 1: Install and Secure MariaDB
- name: Install MariaDB packages
ansible.builtin.dnf:
name:
- mariadb-server
- mariadb
state: present
tags: [mariadb]
- name: Start and enable MariaDB service
ansible.builtin.service:
name: mariadb
state: started
enabled: yes
tags: [mariadb]
notify: Restart MariaDB
- name: Ensure MySQL root password is set (secure setup)
community.mysql.mysql_user:
name: root
host: localhost
password: "{{ mysql_root_password }}" # From vars file, encrypted with Vault
login_user: root
login_password: "" # Initial blank password
state: present
ignore_errors: yes # Handle cases where password is already set
no_log: true # Do not log sensitive info
tags: [mariadb]
- name: Create Zabbix Proxy database
community.mysql.mysql_db:
name: "{{ zabbix_db_name }}" # e.g., zabbix_proxy
state: present
login_user: root
login_password: "{{ mysql_root_password }}"
no_log: true
tags: [mariadb, zabbix]
- name: Create Zabbix Proxy database user and grant privileges
community.mysql.mysql_user:
name: "{{ zabbix_db_user }}" # e.g., zabbix_proxy_user
password: "{{ zabbix_db_password }}" # From vars file, encrypted with Vault
priv: '{{ zabbix_db_name }}.*:ALL' # Grant all on the specific database
state: present
login_user: root
login_password: "{{ mysql_root_password }}"
no_log: true
tags: [mariadb, zabbix]
# Section 2: Add Zabbix Repository and Install Zabbix Proxy
- name: Add Zabbix repository
ansible.builtin.dnf_repository:
name: zabbix
description: Zabbix Official Repository
baseurl: http://repo.zabbix.com/zabbix/{{ zabbix_version }}/rhel/9/x86_64/ # Use latest version variable
gpgcheck: yes
gpgkey: http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-A14
state: present
tags: [zabbix]
- name: Install Zabbix Proxy package
ansible.builtin.dnf:
name: zabbix-proxy-mysql # MySQL variant for MariaDB compatibility
state: latest
tags: [zabbix]
notify: Restart Zabbix Proxy
# Section 3: Generate and Configure PSK Encryption
- name: Generate PSK key for Zabbix Proxy
ansible.builtin.command: openssl rand -hex 32
register: psk_key_output
changed_when: false # This task is not idempotent, but we check for changes
no_log: true # Do not log the PSK
tags: [zabbix, psk]
- name: Write PSK key to secure file
ansible.builtin.copy:
content: "{{ psk_key_output.stdout }}\n"
dest: /etc/zabbix/zabbix_proxy.psk
owner: zabbix
group: zabbix
mode: 0400 # Read-only by owner
no_log: true
tags: [zabbix, psk]
notify: Restart Zabbix Proxy
# Section 4: Configure Zabbix Proxy
- name: Configure Zabbix Proxy configuration file
ansible.builtin.template:
src: templates/zabbix_proxy.conf.j2 # Jinja2 template file
dest: /etc/zabbix/zabbix_proxy.conf
owner: zabbix
group: zabbix
mode: 0640
notify: Restart Zabbix Proxy
tags: [zabbix]
handlers:
- name: Restart MariaDB
ansible.builtin.service:
name: mariadb
state: restarted
- name: Restart Zabbix Proxy
ansible.builtin.service:
name: zabbix-proxy
state: restarted
post_tasks:
- name: Ensure Zabbix Proxy service is started and enabled
ansible.builtin.service:
name: zabbix-proxy
state: started
enabled: yes
tags: [zabbix]