much tidying up
This commit is contained in:
@ -4,6 +4,7 @@ pipeline {
|
||||
// Define parameters
|
||||
parameters {
|
||||
string(name: 'host_ip', description: 'Target System Address')
|
||||
booleanParam(name: 'server_only', defaultValue: false, description: 'Check this to skip desktop packages')
|
||||
}
|
||||
|
||||
environment {
|
||||
@ -21,12 +22,16 @@ pipeline {
|
||||
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/update-endpoint.yaml"
|
||||
cd /var/jenkins_home/ansible
|
||||
chmod +x /var/jenkins_home/ansible/inventory/inventory.sh
|
||||
/var/jenkins_home/ansible/inventory/inventory.sh -a \$jenkins_subnet_group -g \$jenkins_group -u \$jenkins_user -i ${params.host_ip}
|
||||
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}
|
||||
"""
|
||||
}
|
||||
}
|
||||
@ -36,14 +41,18 @@ 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/update-endpoint.yaml"
|
||||
set -x
|
||||
|
||||
cd /var/jenkins_home/ansible
|
||||
|
||||
ansible-playbook -i \$inventory_file /var/jenkins_home/ansible/playbooks/update-endpoint.yaml \
|
||||
--ssh-common-args='-o StrictHostKeyChecking=no'
|
||||
ansible-playbook -i \$inventory_file \$playbook_file \
|
||||
--ssh-common-args='-o StrictHostKeyChecking=no' \
|
||||
--extra-vars " server_only=${params.server_only} "
|
||||
|
||||
"""
|
||||
}
|
||||
@ -54,8 +63,11 @@ pipeline {
|
||||
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
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user