much tidying up

This commit is contained in:
2026-03-29 21:46:33 -07:00
parent a201c7919a
commit e95dd3efd5
30 changed files with 944 additions and 186 deletions

View File

@ -0,0 +1,76 @@
pipeline {
agent any
// Define parameters
parameters {
string(name: 'host_ip', description: 'Target System Address')
}
environment {
ANSIBLE_FORCE_COLOR = '1'
SSH_CREDENTIALS_ID = 'jenkins-ssh-key'
SATURN_BEHEMOTH = credentials('SATURN_BEHEMOTH')
}
options {
ansiColor('xterm')
}
stages {
stage('Generate Inventory File') {
steps {
// Generate the dynamic inventory file
sh """
set +x
jenkins_group=\$(echo ${env.BUILD_USER_GROUPS} | sed 's/,/\\n/g' | grep -v \$SERVER_SUBNET_GROUP | grep Jenkins | head -n 1)
jenkins_subnet_group=\$(echo ${env.BUILD_USER_GROUPS} | sed 's/,/\\n/g' | grep -e authenticated -e \$SERVER_SUBNET_GROUP | sort -rf | head -n 1)
jenkins_user=\$(echo ${env.BUILD_USER})
playbook_file="/var/jenkins_home/ansible/playbooks/guac-capture.yaml"
cd /var/jenkins_home/ansible
chmod +x /var/jenkins_home/ansible/inventory/inventory.sh
set -x
/var/jenkins_home/ansible/inventory/inventory.sh -p \$playbook_file -s -a \$jenkins_subnet_group -g \$jenkins_group -u \$jenkins_user -i ${params.host_ip}
"""
}
}
stage('Ansible Pipeline') {
steps {
//Run the cosmos-base ansible playbook
sh """
set +x
echo ${params.host_ip}
hash=\$(echo -n ${params.host_ip} | md5sum | cut -c 1-8)
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
playbook_file="/var/jenkins_home/ansible/playbooks/guac-capture.yaml"
set -x
cd /var/jenkins_home/ansible
ansible-playbook -i \$inventory_file \$playbook_file \
--ssh-common-args='-o StrictHostKeyChecking=no' \
--extra-vars "saturn_behemoth=${SATURN_BEHEMOTH} "
"""
}
}
}
post {
always {
// Remove dynamic Inventory file
sh """
set +x
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
set -x
rm \$inventory_file
"""
}
}
}