Ansible-ZabbixAgent/roles/zabbixAgent/tasks/main.yml

64 lines
1.7 KiB
YAML
Raw Normal View History

2024-11-24 16:59:28 -07:00
---
# file: roles/zabbixAgent/tasks/main.yml
- name: Check if epel enabled
stat:
path: /etc/yum.repos.d/epel.repo
register: epel_result
- name: Exclude Zabbix if epel enabled
yum_repository:
name: epel
file: epel
metalink: "https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir"
description: "Extra Packages for Enterprise Linux $releasever - $basearch"
exclude: "zabbix*"
enabled: true
gpgcheck: true
countme: true
gpgkey: "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever"
when: epel_result.stat.exists
- name: Install Zabbix RPM
package:
name: "{{ zabbixAgent_url }}"
state: present
disable_gpg_check: true
- name: Install ZabbixAgent
package:
name:
- zabbix-agent2
- zabbix-agent2-plugin-*
state: present
- name: Deploy ZabbixAgent configuration file
template:
src: "ansibleZabbixAgent.conf.j2"
dest: "/etc/zabbix/zabbix_agent2.d/ansibleZabbixAgent.conf"
notify: Restart zabbix-agent2
- name: Create psk file
copy:
content: "{{ zabbixAgent_conf_psk_key }}"
dest: "{{ zabbixAgent_conf_psk_file }}"
owner: zabbix
group: zabbix
mode: '0400'
when: zabbixAgent_conf_psk_key != '' and zabbixAgent_conf_psk_file != ''
- name: Enable firewall rule listen_port
firewalld:
port: "{{ zabbixAgent_conf_listen_port }}/tcp"
permanent: yes
immediate: yes
state: enabled
notify: Reload firewalld
when: zabbixAgent_conf_listen_port != ""
- name: Enable ZabbixAgent
service:
name: zabbix-agent2
state: started
enabled: yes