write a playbook for install zabbix
- User
write a playbook for install zabbix
- Assistant
write a playbook for install zabbix
Title: Zabbix Installation Playbook
Hosts: all become: yes tasks:
name: Ensure required packages are present apt: name: "{{ item }}" state: present with_items:
name: Download Zabbix repository key apt_key: url: https://repo.zabbix.com/zabbix-official-repo.key state: present
name: Add Zabbix repository apt_repository: repo: 'deb http://repo.zabbix.com/zabbix/5.0/ubuntu/ focal main' state: present
name: Update apt cache apt: update_cache: yes
name: Install Zabbix server and frontend apt: name: "zabbix-server-mysql" state: present
name: Install Zabbix agent apt: name: "zabbix-agent" state: present
name: Install Zabbix frontend dependencies apt: name: "{{ item }}" state: present with_items:
name: Enable and start Zabbix server service service: name: "zabbix-server" enabled: yes state: started
name: Enable and start Zabbix agent service service: name: "zabbix-agent" enabled: yes state: started
name: Configure PHP timezone for Zabbix lineinfile: path: /etc/php/7.4/apache2/php.ini regex: '^;date.timezone =' line: 'date.timezone = Europe/London' state: present
name: Configure Apache for Zabbix frontend lineinfile: path: /etc/apache2/conf-available/zabbix.conf line: 'php_value[date.timezone] = Europe/London' state: present
name: Enable Zabbix frontend Apache configuration apache2_module: module: rewrite state: present
name: Enable Zabbix frontend configuration command: /usr/sbin/a2enconf zabbix.conf
name: Restart Apache service service: name: apache2 state: restarted
name: Wait for Zabbix database setup wait_for: port: 3306 host: localhost delay: 5 timeout: 300 state: started
name: Import Zabbix database schema command: mysql -u root -e "create database zabbix character set utf8 collate utf8_bin;" become: yes become_user: mysql
name: Import initial Zabbix database schema command: mysql -u root zabbix < /usr/share/doc/zabbix-server-mysql*/create.sql.gz become: yes become_user: mysql
name: Configure Zabbix server database connection lineinfile: path: /etc/zabbix/zabbix_server.conf regex: '^# DBPassword=' line: 'DBPassword=password' backup: yes
name: Restart Zabbix server service service: name: "zabbix-server" state: restarted
name: Configure Zabbix agent to connect to the server lineinfile: path: /etc/zabbix/zabbix_agentd.conf regex: '^Server=' line: 'Server=127.0.0.1' state: present
name: Configure Zabbix agent to listen for connections lineinfile: path: /etc/zabbix/zabbix_agentd.conf regex: '^# ListenIP=' line: 'ListenIP=0.0.0.0' state: present
name: Restart Zabbix agent service service: name: "zabbix-agent" state: restarted
name: Cleanup unnecessary files and services apt: name: "{{ item }}" state: absent with_items:
...
This playbook is an example and might need adjustments based on your specific environment and requirements. It assumes you are using Ubuntu 20.04 (focal) and have root access on the target hosts. Make sure to review and customize the playbook before execution.
Not yet included in a published release.