much tidying up
This commit is contained in:
@ -31,12 +31,15 @@ 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/cosmos-public.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}
|
||||
|
||||
|
||||
"""
|
||||
@ -45,22 +48,36 @@ pipeline {
|
||||
|
||||
stage('Ansible Playbook') {
|
||||
steps {
|
||||
//Run the cosmos-base ansible playbook
|
||||
// /workspace/ansible/playbooks/cosmos-base.yaml
|
||||
//Run the cosmos-public ansible playbook
|
||||
// /workspace/ansible/playbooks/cosmos-public.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/cosmos-public.yaml"
|
||||
extra_vars=\$(echo " \
|
||||
docker_full=true \
|
||||
public_deploy=true \
|
||||
kde_full=false \
|
||||
new_hostname=${params.new_hostname} \
|
||||
rename_host=${params.rename_host} \
|
||||
reboot_host=${params.reboot_host} \
|
||||
local_username=${params.local_username} \
|
||||
reset_user=${params.reset_user} \
|
||||
apps_list=${APPS_LIST} \
|
||||
matt_public_key='${env.matt_public_key}'\
|
||||
cosmos_password='${env.cosmos_password}' \
|
||||
cosmos_root_password='${env.cosmos_root_password}' \
|
||||
" | tr -s " ")
|
||||
set -x
|
||||
|
||||
cd /var/jenkins_home/ansible
|
||||
|
||||
ansible-playbook -i \$inventory_file /var/jenkins_home/ansible/playbooks/cosmos-public.yaml \
|
||||
ansible-playbook -i \$inventory_file \$playbook_file \
|
||||
--ssh-common-args='-o StrictHostKeyChecking=no' \
|
||||
--extra-vars "new_hostname=${params.new_hostname} rename_host=${params.rename_host} reboot_host=${params.reboot_host} \
|
||||
local_username=${params.local_username} kde_full=false apps_list=${APPS_LIST} docker_full=true \
|
||||
reset_user=${params.reset_user} public_deploy=true matt_public_key='${env.matt_public_key}'\
|
||||
cosmos_password='${env.cosmos_password}' cosmos_root_password='${env.cosmos_root_password}' "
|
||||
|
||||
--extra-vars "\$extra_vars"
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
@ -70,8 +87,10 @@ 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