pipeline { agent any // Define parameters parameters { string(name: 'host_ip', description: 'Target System Address') string(name: 'custom_port', defaultValue: "80", description: 'To use something other than 80 on the web dashboard') string(name: 'custom_api_port', defaultValue: "5000", description: 'To use something other than 5000 on the flask API') booleanParam(name: 'public_dashboard', defaultValue: true, description: 'Enable this option to bind the dashboard to 0.0.0.0') booleanParam(name: 'quick_refresh', defaultValue: false, description: 'Enable this option to skip init') booleanParam(name: 'log_output', defaultValue: false, description: 'Enable basic logging') booleanParam(name: 'debug_output', defaultValue: false, description: 'Enable debug logging output') booleanParam(name: 'noisy_test', defaultValue: false, description: 'Enable noisy debug logging') booleanParam(name: 'secure_api', defaultValue: true, description: 'Enable secure API endpoints') booleanParam(name: 'push_redis', defaultValue: true, description: 'Enable redis backend') booleanParam(name: 'run_background', defaultValue: true, description: 'Enable flask background task') booleanParam(name: 'cosmostat_server_reporter', defaultValue: false, description: 'Enable client reporting') booleanParam(name: 'cosmostat_server', defaultValue: false, description: 'Enable cosmostat server') } environment { ANSIBLE_FORCE_COLOR = '1' SATURN_BEHEMOTH = credentials('SATURN_BEHEMOTH') CIFS_CREDENTIALS = credentials("TERRA_BEHEMOTH_SMB") cosmostat_api_key = credentials("cosmostat_api_key") } 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/cosmostat.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 -a \$jenkins_subnet_group -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 """ 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/cosmostat.yaml" extra_vars=\$(echo " \ new_hostname=${params.new_hostname} \ saturn_behemoth=${SATURN_BEHEMOTH} \ CIFS_USERNAME=${env.CIFS_CREDENTIALS_USR} \ CIFS_PASSWORD=${env.CIFS_CREDENTIALS_PSW} \ quick_refresh=${params.quick_refresh} \ noisy_test=${params.noisy_test} \ debug_output=${params.debug_output} \ secure_api=${params.secure_api} \ push_redis=${params.push_redis} \ run_background=${params.run_background} \ log_output=${params.log_output} \ public_dashboard=${params.public_dashboard} \ custom_port=${params.custom_port} \ custom_api_port=${params.custom_api_port} \ cosmostat_server_reporter=${params.cosmostat_server_reporter} \ cosmostat_server=${params.cosmostat_server} \ REAL_API_KEY=${env.cosmostat_api_key} \ " | tr -s " ") set -x cd /var/jenkins_home/ansible ansible-playbook -i \$inventory_file \$playbook_file \ --ssh-common-args='-o StrictHostKeyChecking=no' \ --extra-vars "\$extra_vars" """ } } } 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 """ } } }