Files
zabbix-agent-install/Jenkinsfile
2026-03-13 09:14:07 -04:00

76 lines
2.3 KiB
Groovy

pipeline {
agent any
parameters {
string(
name: 'LIMIT',
defaultValue: '',
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(
name: 'DRY_RUN',
defaultValue: false,
description: 'Run in check mode — no changes will be applied to target hosts'
)
}
environment {
PROXMOX_URL = 'https://192.168.0.166:8006'
PROXMOX_USER = 'dynamic-inventory@pve'
PROXMOX_TOKEN_ID = 'dynamic-inventory'
PROXMOX_TOKEN_SECRET = credentials('PROXMOX_TOKEN_SECRET')
ANSIBLE_HOST_KEY_CHECKING = 'False'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Verify Inventory') {
steps {
sh '''
echo "Testing dynamic inventory connection..."
ansible-inventory -i inventory/inventory.proxmox.yml --graph zabbix_targets
'''
}
}
stage('Run Playbook') {
steps {
script {
def limitFlag = params.LIMIT ? "--limit '${params.LIMIT}'" : ''
def checkFlag = params.DRY_RUN ? '--check --diff' : ''
def stateVar = params.UNINSTALL ? '-e "zabbix_state=absent"' : ''
sh """
ansible-playbook \
-i inventory/inventory.proxmox.yml \
playbooks/install_zabbix.yml \
${limitFlag} \
${checkFlag} \
${stateVar} \
-v
"""
}
}
}
}
post {
success {
echo "Zabbix agent ${params.UNINSTALL ? 'removal' : 'installation'} completed successfully"
}
failure {
echo "Zabbix agent ${params.UNINSTALL ? 'removal' : 'installation'} failed"
}
}
}