much tidying up
This commit is contained in:
112
Jenkinsfile.mc-vizz
Normal file
112
Jenkinsfile.mc-vizz
Normal file
@ -0,0 +1,112 @@
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
|
||||
// Define parameters
|
||||
parameters {
|
||||
string(name: 'host_ip', description: 'Target System Address')
|
||||
//booleanParam(name: 'cosmostat_server', defaultValue: false, description: 'Enable cosmostat server')
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
environment {
|
||||
ANSIBLE_FORCE_COLOR = '1'
|
||||
cosmos_password = credentials('cosmos_password')
|
||||
cosmos_root_password = credentials('cosmos_root_password')
|
||||
jenkins_public_key = credentials('jenkins_public_key')
|
||||
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/cosmos-server.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-server ansible playbook
|
||||
// /workspace/ansible/playbooks/cosmos-server.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/mc_vizz.yaml"
|
||||
extra_vars=\$(echo " \
|
||||
new_hostname=MC-Vizz \
|
||||
saturn_behemoth=${SATURN_BEHEMOTH} \
|
||||
CIFS_USERNAME=${env.CIFS_CREDENTIALS_USR} \
|
||||
CIFS_PASSWORD=${env.CIFS_CREDENTIALS_PSW} \
|
||||
ITMFG_USERNAME=${env.ITMFG_CREDENTIALS_USR} \
|
||||
ITMFG_PASSWORD=${env.ITMFG_CREDENTIALS_PSW} \
|
||||
docker_full=false \
|
||||
rename_host=${params.rename_endpoint} \
|
||||
onboard_pi=${params.onboard_pi} \
|
||||
linux_ldap_pwd=${LINUX_LDAP_PWD} \
|
||||
install_docker=${params.install_docker} \
|
||||
install_LDAP=${params.install_LDAP} \
|
||||
special_server='${params.special_server}' \
|
||||
refresh_special=${params.refresh_special} \
|
||||
pxe_proxy_password=${pxe_proxy_password} \
|
||||
PXE_API_KEY=${PXE_API_KEY} \
|
||||
no_vpn=${params.no_vpn} add_domain=${params.add_domain} \
|
||||
matt_public_key='${env.matt_public_key}' \
|
||||
cosmos_password='${env.cosmos_password}' \
|
||||
cosmos_root_password='${env.cosmos_root_password}' \
|
||||
tesla_api_key='${tesla_api_key}' \
|
||||
public_deploy=${params.public_deploy} \
|
||||
install_python=${params.install_python} \
|
||||
skip_nvidia=${params.skip_nvidia} \
|
||||
intall_cockpit=${params.intall_cockpit} \
|
||||
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 matt_private_key='${env.matt_private_key}'"
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user