much tidying up
This commit is contained in:
@ -44,12 +44,16 @@ pipeline {
|
||||
}
|
||||
// Generate the dynamic inventory files
|
||||
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})
|
||||
cd /var/jenkins_home/ansible
|
||||
chmod +x /var/jenkins_home/ansible/inventory/inventory.sh
|
||||
/var/jenkins_home/ansible/inventory/inventory.sh -s -a \$jenkins_subnet_group -g \$jenkins_group -u \$jenkins_user -i ${params.host_ip}
|
||||
playbook_file="/var/jenkins_home/ansible/playbooks/vm_party.yaml
|
||||
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}
|
||||
echo Stage Two Hash: ${env.STAGE_TWO_HASH}
|
||||
|
||||
"""
|
||||
@ -64,19 +68,30 @@ pipeline {
|
||||
//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/vm_party.yaml
|
||||
extra_vars=\$(echo " \
|
||||
run_stage_two=false \
|
||||
new_hostname=${params.new_hostname} \
|
||||
autologin=${params.autologin} \
|
||||
service_only=${params.service_only} \
|
||||
update_party=${params.update_party} \
|
||||
matt_public_key='${env.matt_public_key}' \
|
||||
cosmos_password='${env.cosmos_password}' \
|
||||
cosmos_root_password='${env.cosmos_root_password}' \
|
||||
STAGE_TWO_HASH=${env.STAGE_TWO_HASH} \
|
||||
vm_party_username_password=${env.vm_party_username_password} \
|
||||
" | tr -s " " )
|
||||
set -x
|
||||
|
||||
cd /var/jenkins_home/ansible
|
||||
|
||||
ansible-playbook -i \$inventory_file /var/jenkins_home/ansible/playbooks/vm_party.yaml \
|
||||
ansible-playbook -i \$inventory_file \$playbook_file \
|
||||
--ssh-common-args='-o StrictHostKeyChecking=no' \
|
||||
--extra-vars "new_hostname=${params.new_hostname} matt_public_key='${env.matt_public_key}' \
|
||||
cosmos_password='${env.cosmos_password}' cosmos_root_password='${env.cosmos_root_password}' \
|
||||
STAGE_TWO_HASH=${env.STAGE_TWO_HASH} update_party=${params.update_party} \
|
||||
run_stage_two=false vm_party_username_password=${env.vm_party_username_password} \
|
||||
autologin=${params.autologin} service_only=${params.service_only} "
|
||||
--extra-vars "\$extra_vars"
|
||||
"""
|
||||
}
|
||||
}
|
||||
@ -111,22 +126,26 @@ pipeline {
|
||||
sleep(waitInterval)
|
||||
}
|
||||
}
|
||||
// check for forbidden subnet
|
||||
|
||||
|
||||
|
||||
// Run the stage two playbook
|
||||
// using the hash
|
||||
sh """
|
||||
|
||||
set +x
|
||||
inventory_file="/var/jenkins_home/ansible/.inv/inventory-${env.STAGE_TWO_HASH}.yml"
|
||||
playbook_file="/var/jenkins_home/ansible/playbooks/vm_party.yaml"
|
||||
extra_vars="\$(echo " \
|
||||
run_stage_two=true \
|
||||
vm_party_username_password=${env.vm_party_username_password} \
|
||||
service_only=${params.service_only} \
|
||||
" | tr -s " " )
|
||||
set -x
|
||||
|
||||
cd /var/jenkins_home/ansible
|
||||
|
||||
ansible-playbook -i \$inventory_file /var/jenkins_home/ansible/playbooks/vm_party.yaml \
|
||||
ansible-playbook -i \$inventory_file \$playbook_file \
|
||||
--ssh-common-args='-o StrictHostKeyChecking=no' \
|
||||
--extra-vars "run_stage_two=true vm_party_username_password=${env.vm_party_username_password} \
|
||||
service_only=${params.service_only} "
|
||||
--extra-vars "\$extra_vars"
|
||||
|
||||
"""
|
||||
}
|
||||
@ -137,12 +156,14 @@ pipeline {
|
||||
always {
|
||||
// Remove dynamic Inventory files
|
||||
sh """
|
||||
set +x
|
||||
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
|
||||
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
|
||||
rm \$inventory_file || true
|
||||
inventory_file_1="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
|
||||
inventory_file_2="/var/jenkins_home/ansible/.inv/inventory-${env.STAGE_TWO_HASH}.yml"
|
||||
set -x
|
||||
|
||||
inventory_file="/var/jenkins_home/ansible/.inv/inventory-${env.STAGE_TWO_HASH}.yml"
|
||||
rm \$inventory_file || true
|
||||
rm \$inventory_file_1 || true
|
||||
rm \$inventory_file_2 || true
|
||||
|
||||
"""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user