98 lines
4.7 KiB
Plaintext
98 lines
4.7 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
// Define parameters
|
|
parameters {
|
|
//booleanParam(name: 'deploy_iso', defaultValue: true, description: 'Deploy extra ISO boot options - will increase pipeline runtime.')
|
|
string(name: 'host_ip', defaultValue: '172.20.20.41', description: 'PXE Server IP Address')
|
|
string(name: 'iface', defaultValue: 'eth1', description: 'Listen interface for PXE')
|
|
string(name: 'server_ip', defaultValue: '172.29.1.10', description: 'IP address for DHCP server, might not match the target IP such as in the default case where I have two interfaces')
|
|
string(name: 'router_ip', defaultValue: '172.29.1.10', description: 'IP Address for router')
|
|
string(name: 'dhcp_subnet', defaultValue: '172.29.1.0', description: 'Default Subnet for DHCP server')
|
|
string(name: 'dhcp_netmask', defaultValue: '255.255.255.0', description: 'Default netmask for DHCP server')
|
|
string(name: 'dhcp_start', defaultValue: '172.29.1.50', description: 'DHCP start IP')
|
|
string(name: 'dhcp_end', defaultValue: '172.29.1.250', description: 'DHCP end IP')
|
|
booleanParam(name: 'configure_routing', defaultValue: true, description: 'Check this option to configure the PXE server to be the gateway for the dhcp network')
|
|
string(name: 'inet_iface', defaultValue: 'eth0', description: 'Interface for internet if enabling routing')
|
|
booleanParam(name: 'refresh_only', defaultValue: true, description: 'Only run the PXE Role to refresh configs')
|
|
}
|
|
|
|
environment {
|
|
ANSIBLE_FORCE_COLOR = '1'
|
|
SATURN_BEHEMOTH = credentials('SATURN_BEHEMOTH')
|
|
APPS_LIST = 'pxe-server'
|
|
pxe_proxy_password = credentials('pxe_proxy_password')
|
|
PXE_API_KEY = credentials('PXE_API_KEY')
|
|
LINUX_LDAP_PWD = credentials('LINUX_LDAP')
|
|
AUTHORIZED_KEY = credentials('AUTH_SSH_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 -s -g \$jenkins_group -u \$jenkins_user -i ${params.host_ip}
|
|
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('Ansible Playbook') {
|
|
steps {
|
|
//Run the pxe-server ansible playbook
|
|
// /workspace/ansible/playbooks/pxe-server.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/pxe-server.yaml \
|
|
--ssh-common-args='-o StrictHostKeyChecking=no' \
|
|
--extra-vars "new_hostname=debian-pxe.home.cosmos saturn_behemoth=${SATURN_BEHEMOTH} authorized_key=${AUTHORIZED_KEY} \
|
|
rename_host=true apps_list=${APPS_LIST} listen_interface=${params.iface} pxe_auth=${pxe_proxy_password} \
|
|
internet_interface=${params.inet_iface} dhcp_subnet=${params.dhcp_subnet} \
|
|
dhcp_netmask=${params.dhcp_netmask} dhcp_start=${params.dhcp_start} \
|
|
dhcp_end=${params.dhcp_end} server_ip=${params.server_ip} \
|
|
router_ip=${params.router_ip} configure_routing=${params.configure_routing} \
|
|
refresh_only=${params.refresh_only} \
|
|
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
|
|
|
|
"""
|
|
}
|
|
}
|
|
|
|
}
|