init commit
This commit is contained in:
155
Jenkinsfile.cosmos-server
Normal file
155
Jenkinsfile.cosmos-server
Normal file
@ -0,0 +1,155 @@
|
||||
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')
|
||||
booleanParam(name: 'add_domain', defaultValue: true, description: 'When checked hostname will have home.cosmos appended')
|
||||
// reference for later
|
||||
// choice(name: 'DEPLOY_ENV', choices: ['dev', 'staging', 'prod'], description: 'Environment to deploy to')
|
||||
booleanParam(name: 'install_docker', defaultValue: true, description: 'When checked docker packages are installed and portainer started on 9100')
|
||||
booleanParam(name: 'install_LDAP', defaultValue: false, description: 'When checked LDAP integration is installed with NSLCD')
|
||||
choice(name: 'special_server', choices: ['none', 'Octoprint', 'Kodi', 'Timelapse', 'Build ISO', 'Jenkins VPN', 'Net Bridge', 'Carputer', 'VCR Capture'], description: 'Choose special server install if desired')
|
||||
booleanParam(name: 'refresh_special', defaultValue: false, description: 'When checked only the special server step is run')
|
||||
booleanParam(name: 'no_vpn', defaultValue: false, description: 'Check this option to remove default cosmos VPN')
|
||||
booleanParam(name: 'public_deploy', defaultValue: true, description: 'Uncheck this option to deploy private SSH key')
|
||||
booleanParam(name: 'onboard_pi', defaultValue: false, description: 'Check this option to onboard a new FriendlyElec Device')
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
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')
|
||||
jenkins_public_key = credentials('jenkins_public_key')
|
||||
tesla_api_key = credentials('tesla_api_key')
|
||||
}
|
||||
|
||||
options {
|
||||
ansiColor('xterm')
|
||||
}
|
||||
|
||||
stages {
|
||||
|
||||
|
||||
stage('Inject Auth Key') {
|
||||
when {
|
||||
expression { params.onboard_pi }
|
||||
}
|
||||
steps {
|
||||
script{
|
||||
// clear ssh keys
|
||||
echo "Target IP: ${params.host_ip}"
|
||||
|
||||
sh """
|
||||
ssh-keygen -f "/root/.ssh/known_hosts" -R "${params.host_ip}"
|
||||
"""
|
||||
|
||||
}
|
||||
|
||||
script{
|
||||
sh """
|
||||
echo Copy public key to pi home dir
|
||||
sshpass -p 'pi' ssh -o StrictHostKeyChecking=no pi@${params.host_ip} "echo ${env.jenkins_public_key} > /home/pi/authorized_keys"
|
||||
|
||||
"""
|
||||
}
|
||||
|
||||
script{
|
||||
sh """
|
||||
echo Make sure /root/.ssh exists
|
||||
sshpass -p 'pi' ssh -o StrictHostKeyChecking=no pi@${params.host_ip} "echo pi | sudo -S mkdir -p /root/.ssh/"
|
||||
"""
|
||||
}
|
||||
|
||||
script{
|
||||
sh """
|
||||
echo Move public key to root
|
||||
sshpass -p 'pi' ssh -o StrictHostKeyChecking=no pi@${params.host_ip} "echo pi | sudo -S mv /home/pi/authorized_keys /root/.ssh/authorized_keys"
|
||||
|
||||
"""
|
||||
}
|
||||
|
||||
script{
|
||||
sh """
|
||||
echo Restrict permissions on file
|
||||
sshpass -p 'pi' ssh -o StrictHostKeyChecking=no pi@${params.host_ip} "echo pi | sudo -S chmod -R 600 /root/.ssh/"
|
||||
|
||||
"""
|
||||
}
|
||||
|
||||
script{
|
||||
sh """
|
||||
echo Set owner to root
|
||||
sshpass -p 'pi' ssh -o StrictHostKeyChecking=no pi@${params.host_ip} "echo pi | sudo -S chown -R root:root /root/.ssh/"
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stage('Generate Inventory File') {
|
||||
steps {
|
||||
// Generate the dynamic inventory file
|
||||
sh """
|
||||
cd /var/jenkins_home/ansible
|
||||
chmod +x /var/jenkins_home/ansible/inventory/inventory.sh
|
||||
/var/jenkins_home/ansible/inventory/inventory.sh ${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-server.yaml --ssh-common-args='-o StrictHostKeyChecking=no' \
|
||||
--extra-vars "new_hostname=${params.new_hostname} saturn_behemoth=${SATURN_BEHEMOTH} \
|
||||
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}' matt_private_key='${env.matt_private_key}' \
|
||||
cosmos_password='${env.cosmos_password}' cosmos_root_password='${env.cosmos_root_password}' \
|
||||
tesla_api_key='${tesla_api_key}' public_deploy=${params.public_deploy}"
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user