88 lines
3.6 KiB
Plaintext
88 lines
3.6 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
// Define parameters
|
|
parameters {
|
|
string(name: 'host_ip', description: 'Target System Address')
|
|
string(name: 'new_hostname', description: 'Update Hostname')
|
|
booleanParam(name: 'rename_endpoint', defaultValue: true, description: 'Uncheck to skip renaming of endpoint')
|
|
// reference for later
|
|
// choice(name: 'DEPLOY_ENV', choices: ['dev', 'staging', 'prod'], description: 'Environment to deploy to')
|
|
choice(name: 'console_type', choices: ['game boy', 'snes', 'n64'], description: 'Choose special server install if desired')
|
|
}
|
|
|
|
environment {
|
|
ANSIBLE_FORCE_COLOR = '1'
|
|
SATURN_BEHEMOTH = credentials('SATURN_BEHEMOTH')
|
|
APPS_LIST = 'cosmos-base'
|
|
LINUX_LDAP_PWD = credentials('LINUX_LDAP')
|
|
pxe_proxy_password = credentials('pxe_proxy_password')
|
|
PXE_API_KEY = credentials('PXE_API_KEY')
|
|
matt_public_key = credentials('matt_public_key')
|
|
matt_private_key = credentials('matt_private_key')
|
|
cosmos_password = credentials('cosmos_password')
|
|
cosmos_root_password = credentials('cosmos_root_password')
|
|
}
|
|
|
|
options {
|
|
ansiColor('xterm')
|
|
}
|
|
|
|
stages {
|
|
|
|
|
|
stage('Generate Inventory File') {
|
|
steps {
|
|
// Generate the dynamic inventory file
|
|
sh """
|
|
jenkins_group=\$(echo ${env.BUILD_USER_GROUPS} | sed 's/,/\\n/g' | grep Jenkins | 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 -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 """
|
|
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"
|
|
|
|
cd /var/jenkins_home/ansible
|
|
|
|
ansible-playbook -i \$inventory_file /var/jenkins_home/ansible/playbooks/cosmos-console.yaml \
|
|
--ssh-common-args='-o StrictHostKeyChecking=no' \
|
|
--extra-vars "docker_full=falsei nstall_docker=false install_LDAP=false\
|
|
new_hostname=${params.new_hostname}.home.cosmos saturn_behemoth=${SATURN_BEHEMOTH} \
|
|
rename_host=${params.rename_endpoint} console_type=${params.console_type} \
|
|
linux_ldap_pwd=${LINUX_LDAP_PWD} PXE_API_KEY=${PXE_API_KEY} \
|
|
refresh_special=${params.refresh_special} pxe_proxy_password=${pxe_proxy_password} \
|
|
matt_public_key='${env.matt_public_key}' matt_private_key='${env.matt_private_key}' \
|
|
cosmos_password='${env.cosmos_password}' cosmos_root_password='${env.cosmos_root_password}' "
|
|
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
always {
|
|
// Remove dynamic Inventory file
|
|
sh """
|
|
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
|
|
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
|
|
rm \$inventory_file
|
|
|
|
"""
|
|
}
|
|
}
|
|
|
|
}
|