Added uninstall feature
This commit is contained in:
11
Jenkinsfile
vendored
11
Jenkinsfile
vendored
@@ -7,6 +7,11 @@ pipeline {
|
|||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
description: 'Limit to specific hosts or groups (e.g., "vms", "lxcs", "zabbix_targets", or hostname) no .lan required'
|
description: 'Limit to specific hosts or groups (e.g., "vms", "lxcs", "zabbix_targets", or hostname) no .lan required'
|
||||||
)
|
)
|
||||||
|
booleanParam(
|
||||||
|
name: 'UNINSTALL',
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'Remove Zabbix agent2 and purge configuration from target hosts'
|
||||||
|
)
|
||||||
booleanParam(
|
booleanParam(
|
||||||
name: 'DRY_RUN',
|
name: 'DRY_RUN',
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
@@ -43,6 +48,7 @@ pipeline {
|
|||||||
script {
|
script {
|
||||||
def limitFlag = params.LIMIT ? "--limit '${params.LIMIT}'" : ''
|
def limitFlag = params.LIMIT ? "--limit '${params.LIMIT}'" : ''
|
||||||
def checkFlag = params.DRY_RUN ? '--check --diff' : ''
|
def checkFlag = params.DRY_RUN ? '--check --diff' : ''
|
||||||
|
def stateVar = params.UNINSTALL ? '-e "zabbix_state=absent"' : ''
|
||||||
|
|
||||||
sh """
|
sh """
|
||||||
ansible-playbook \
|
ansible-playbook \
|
||||||
@@ -50,6 +56,7 @@ pipeline {
|
|||||||
playbooks/install_zabbix.yml \
|
playbooks/install_zabbix.yml \
|
||||||
${limitFlag} \
|
${limitFlag} \
|
||||||
${checkFlag} \
|
${checkFlag} \
|
||||||
|
${stateVar} \
|
||||||
-v
|
-v
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
@@ -59,10 +66,10 @@ pipeline {
|
|||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "Zabbix agent installation completed successfully"
|
echo "Zabbix agent ${params.UNINSTALL ? 'removal' : 'installation'} completed successfully"
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "Zabbix agent installation failed"
|
echo "Zabbix agent ${params.UNINSTALL ? 'removal' : 'installation'} failed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
---
|
---
|
||||||
|
zabbix_state: "present"
|
||||||
zabbix_server: "zabbix.lan"
|
zabbix_server: "zabbix.lan"
|
||||||
zabbix_version: "7.0"
|
zabbix_version: "7.0"
|
||||||
zabbix_release: "7.0-2"
|
zabbix_release: "7.0-2"
|
||||||
|
|||||||
@@ -1,43 +1,51 @@
|
|||||||
---
|
---
|
||||||
|
# Install tasks
|
||||||
- name: Download Zabbix repository package
|
- name: Download Zabbix repository package
|
||||||
ansible.builtin.get_url:
|
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"
|
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
|
dest: /tmp/zabbix-release.deb
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
|
when: zabbix_state == 'present'
|
||||||
|
|
||||||
- name: Install Zabbix repository package
|
- name: Install Zabbix repository package
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
deb: /tmp/zabbix-release.deb
|
deb: /tmp/zabbix-release.deb
|
||||||
|
when: zabbix_state == 'present'
|
||||||
|
|
||||||
- name: Install Zabbix agent2
|
- name: Install Zabbix agent2
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: zabbix-agent2
|
name: zabbix-agent2
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
when: zabbix_state == 'present'
|
||||||
|
|
||||||
- name: Configure Zabbix server address
|
- name: Configure Zabbix server address
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/zabbix/zabbix_agent2.conf
|
path: /etc/zabbix/zabbix_agent2.conf
|
||||||
regexp: '^Server='
|
regexp: '^Server='
|
||||||
line: "Server={{ zabbix_server }}"
|
line: "Server={{ zabbix_server }}"
|
||||||
|
when: zabbix_state == 'present'
|
||||||
|
|
||||||
- name: Configure Zabbix active server address
|
- name: Configure Zabbix active server address
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/zabbix/zabbix_agent2.conf
|
path: /etc/zabbix/zabbix_agent2.conf
|
||||||
regexp: '^ServerActive='
|
regexp: '^ServerActive='
|
||||||
line: "ServerActive={{ zabbix_server }}"
|
line: "ServerActive={{ zabbix_server }}"
|
||||||
|
when: zabbix_state == 'present'
|
||||||
|
|
||||||
- name: Configure Zabbix agent hostname
|
- name: Configure Zabbix agent hostname
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/zabbix/zabbix_agent2.conf
|
path: /etc/zabbix/zabbix_agent2.conf
|
||||||
regexp: '^Hostname='
|
regexp: '^Hostname='
|
||||||
line: "Hostname={{ ansible_hostname }}"
|
line: "Hostname={{ ansible_hostname }}"
|
||||||
|
when: zabbix_state == 'present'
|
||||||
|
|
||||||
- name: Configure Zabbix agent listen IP
|
- name: Configure Zabbix agent listen IP
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /etc/zabbix/zabbix_agent2.conf
|
path: /etc/zabbix/zabbix_agent2.conf
|
||||||
regexp: '^#?ListenIP='
|
regexp: '^#?ListenIP='
|
||||||
line: "ListenIP=127.0.0.1"
|
line: "ListenIP=127.0.0.1"
|
||||||
|
when: zabbix_state == 'present'
|
||||||
|
|
||||||
- name: Enable and start Zabbix agent2
|
- name: Enable and start Zabbix agent2
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
@@ -45,3 +53,33 @@
|
|||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: true
|
||||||
daemon_reload: 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