75 lines
2.9 KiB
Plaintext
75 lines
2.9 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
// Define parameters
|
|
parameters {
|
|
string(name: 'host_ip', defaultValue: '10.250.128.10', description: 'Target System Address')
|
|
string(name: 'chrome_resolution', defaultValue: '720,1000', description: 'Chrome App Resolution')
|
|
// reference for later
|
|
// choice(name: 'DEPLOY_ENV', choices: ['dev', 'staging', 'prod'], description: 'Environment to deploy to')
|
|
booleanParam(name: 'run_test', defaultValue: false, description: 'Check this to run a test LLDP scan')
|
|
booleanParam(name: 'refresh_only', defaultValue: false, description: 'Check this to re-run on existing LLDP Scan device')
|
|
}
|
|
|
|
environment {
|
|
ANSIBLE_FORCE_COLOR = '1'
|
|
SATURN_BEHEMOTH = credentials('SATURN_BEHEMOTH')
|
|
matt_public_key = credentials('matt_public_key')
|
|
cosmos_password = credentials('cosmos_password')
|
|
cosmos_root_password = credentials('cosmos_root_password')
|
|
}
|
|
|
|
options {
|
|
ansiColor('xterm')
|
|
}
|
|
|
|
stages {
|
|
|
|
|
|
stage('Generate Inventory File') {
|
|
steps {
|
|
// Generate the dynamic inventory file
|
|
sh """
|
|
jenkins_group=\$(echo ${env.BUILD_USER_GROUPS} | sed 's/,/\\n/g' | grep Jenkins | head -n 1)
|
|
jenkins_user=\$(echo ${env.BUILD_USER})
|
|
cd /var/jenkins_home/ansible
|
|
chmod +x /var/jenkins_home/ansible/inventory/inventory.sh
|
|
/var/jenkins_home/ansible/inventory/inventory.sh -g \$jenkins_group -u \$jenkins_user -i ${params.host_ip}
|
|
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('Ansible Playbook') {
|
|
steps {
|
|
//Run the cosmos-base ansible playbook
|
|
// /workspace/ansible/playbooks/cosmos-base.yaml
|
|
sh """
|
|
cd /var/jenkins_home/ansible
|
|
|
|
ansible-playbook -i /var/jenkins_home/ansible/.inv/inventory-${params.host_ip}.yml \
|
|
/var/jenkins_home/ansible/playbooks/lldp-scan.yaml --ssh-common-args='-o StrictHostKeyChecking=no' \
|
|
--extra-vars "new_hostname=MC-LLDP fixed_size='--window-size=${params.chrome_resolution}' \
|
|
run_test=${params.run_test} rename_host=true refresh_only=${params.refresh_only} \
|
|
public_deploy=true no_vpn=true matt_public_key='${env.matt_public_key}' \
|
|
cosmos_password='${env.cosmos_password}' cosmos_root_password='${env.cosmos_root_password}' "
|
|
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
always {
|
|
// Remove dynamic Inventory file
|
|
sh """
|
|
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
|
|
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
|
|
rm \$inventory_file
|
|
|
|
"""
|
|
}
|
|
}
|
|
|
|
}
|