Files
zabbix-agent-install/roles/zabbix_agent/tasks/main.yml

48 lines
1.4 KiB
YAML

---
- name: Download Zabbix repository package
ansible.builtin.get_url:
url: "https://repo.zabbix.com/zabbix/{{ zabbix_version }}/ubuntu/pool/main/z/zabbix-release/zabbix-release_{{ zabbix_release }}+ubuntu{{ ansible_distribution_version }}_all.deb"
dest: /tmp/zabbix-release.deb
mode: '0644'
- name: Install Zabbix repository package
ansible.builtin.apt:
deb: /tmp/zabbix-release.deb
- name: Install Zabbix agent2
ansible.builtin.apt:
name: zabbix-agent2
state: present
update_cache: true
- name: Configure Zabbix server address
ansible.builtin.lineinfile:
path: /etc/zabbix/zabbix_agent2.conf
regexp: '^Server='
line: "Server={{ zabbix_server }}"
- name: Configure Zabbix active server address
ansible.builtin.lineinfile:
path: /etc/zabbix/zabbix_agent2.conf
regexp: '^ServerActive='
line: "ServerActive={{ zabbix_server }}"
- name: Configure Zabbix agent hostname
ansible.builtin.lineinfile:
path: /etc/zabbix/zabbix_agent2.conf
regexp: '^Hostname='
line: "Hostname={{ ansible_hostname }}"
- name: Configure Zabbix agent listen IP
ansible.builtin.lineinfile:
path: /etc/zabbix/zabbix_agent2.conf
regexp: '^#?ListenIP='
line: "ListenIP=127.0.0.1"
- name: Enable and start Zabbix agent2
ansible.builtin.systemd:
name: zabbix-agent2
state: started
enabled: true
daemon_reload: true