first commit

This commit is contained in:
2026-01-30 14:49:44 -05:00
commit eb829c624c
5 changed files with 210 additions and 0 deletions

95
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,95 @@
pipeline {
agent any
parameters {
choice(
name: 'PLAYBOOK',
choices: ['dockerUpdate.yml', 'dockerPrune.yaml'],
description: 'Select the playbook to run'
)
string(
name: 'LIMIT',
defaultValue: '',
description: 'Limit to specific hosts or groups (e.g., "vms", "lxcs", "update_targets", or hostname) no.lan required'
)
booleanParam(
name: 'DRY_RUN',
defaultValue: false,
description: 'Run in check mode (no changes made)'
)
}
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 inventories/inventory.proxmox.yml --list | head -10
'''
}
}
stage('Run Playbook') {
steps {
script {
def dockerPlaybooks = ['dockerUpdate.yml', 'dockerPrune.yaml']
def isDockerPlaybook = params.PLAYBOOK in dockerPlaybooks
// Build the limit flag
def limitValue = ''
if (isDockerPlaybook) {
// Docker playbooks always target 'docker' tagged hosts
// If user provides a limit, use intersection (docker AND limit)
limitValue = params.LIMIT ? "docker:&${params.LIMIT}" : 'docker'
} else {
limitValue = params.LIMIT ?: ''
}
def limitFlag = limitValue ? "--limit '${limitValue}'" : ''
def checkFlag = (params.DRY_RUN == true) ? '--check --diff' : ''
def extraVars = (params.CLEANUP_SNAPSHOTS == true) ? "-e cleanup_old_snapshots=true" : ''
echo "DRY_RUN parameter: ${params.DRY_RUN}"
echo "Check flag: '${checkFlag}'"
echo "Limit: '${limitValue}'"
if (isDockerPlaybook) {
echo "Docker playbook detected - targeting hosts with 'docker' tag"
}
sh """
ansible-playbook \
-i inventories/inventory.proxmox.yml \
playbooks/${params.PLAYBOOK} \
${limitFlag} \
${checkFlag} \
${extraVars} \
-v
"""
}
}
}
}
post {
success {
echo "Playbook ${params.PLAYBOOK} completed successfully"
}
failure {
echo "Playbook ${params.PLAYBOOK} failed"
}
}
}