Added uninstall feature
This commit is contained in:
@@ -1,43 +1,51 @@
|
||||
---
|
||||
# Install tasks
|
||||
- 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'
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
- name: Install Zabbix repository package
|
||||
ansible.builtin.apt:
|
||||
deb: /tmp/zabbix-release.deb
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
- name: Install Zabbix agent2
|
||||
ansible.builtin.apt:
|
||||
name: zabbix-agent2
|
||||
state: present
|
||||
update_cache: true
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
- name: Configure Zabbix server address
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/zabbix/zabbix_agent2.conf
|
||||
regexp: '^Server='
|
||||
line: "Server={{ zabbix_server }}"
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
- name: Configure Zabbix active server address
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/zabbix/zabbix_agent2.conf
|
||||
regexp: '^ServerActive='
|
||||
line: "ServerActive={{ zabbix_server }}"
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
- name: Configure Zabbix agent hostname
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/zabbix/zabbix_agent2.conf
|
||||
regexp: '^Hostname='
|
||||
line: "Hostname={{ ansible_hostname }}"
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
- name: Configure Zabbix agent listen IP
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/zabbix/zabbix_agent2.conf
|
||||
regexp: '^#?ListenIP='
|
||||
line: "ListenIP=127.0.0.1"
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
- name: Enable and start Zabbix agent2
|
||||
ansible.builtin.systemd:
|
||||
@@ -45,3 +53,33 @@
|
||||
state: started
|
||||
enabled: true
|
||||
daemon_reload: true
|
||||
when: zabbix_state == 'present'
|
||||
|
||||
# Uninstall tasks
|
||||
- name: Stop and disable Zabbix agent2
|
||||
ansible.builtin.systemd:
|
||||
name: zabbix-agent2
|
||||
state: stopped
|
||||
enabled: false
|
||||
when: zabbix_state == 'absent'
|
||||
ignore_errors: true
|
||||
|
||||
- name: Remove Zabbix agent2 package
|
||||
ansible.builtin.apt:
|
||||
name: zabbix-agent2
|
||||
state: absent
|
||||
purge: true
|
||||
when: zabbix_state == 'absent'
|
||||
|
||||
- name: Remove Zabbix repository package
|
||||
ansible.builtin.apt:
|
||||
name: zabbix-release
|
||||
state: absent
|
||||
purge: true
|
||||
when: zabbix_state == 'absent'
|
||||
|
||||
- name: Remove Zabbix configuration directory
|
||||
ansible.builtin.file:
|
||||
path: /etc/zabbix
|
||||
state: absent
|
||||
when: zabbix_state == 'absent'
|
||||
|
||||
Reference in New Issue
Block a user