166 lines
7.6 KiB
Plaintext
166 lines
7.6 KiB
Plaintext
pipeline {
|
|
agent any
|
|
// Define parameters
|
|
parameters {
|
|
string(name: 'host_ip', description: 'Target System Address')
|
|
text(name: 'kiosk_variable', defaultValue: '- chrome_website: "http://localhost:8081"\n service_name: user_stream_control\n service_description: "VCR Capture User Stream Control"\n extra_service_configs: ""\n user_data_dir: "/opt/chrome/one"\n extra_chrome_configs: |\n --window-size="560,1080" \\\n --user-data-dir=/opt/chrome/one \\\n- chrome_website: "http://localhost:8888/stream"\n service_name: stream_preview\n service_description: "VCR Capture Preview Stream"\n extra_service_configs: ""\n user_data_dir: "/opt/chrome/two"\n extra_chrome_configs: |\n --window-size="1350,1080" \\\n --user-data-dir=/opt/chrome/two \\\n --window-position="570,0" \\\n', description: 'Kiosk variables to deploy, default example should show everything you might need. It is processed as an ansible variable')
|
|
string(name: 'new_hostname', defaultValue: 'MC-Kiosk', 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')
|
|
booleanParam(name: 'install_docker', defaultValue: true, description: 'When checked docker packages are installed and portainer started on 9100')
|
|
booleanParam(name: 'onboard_pi', defaultValue: false, description: 'Check this option to onboard a new FriendlyElec Device')
|
|
booleanParam(name: 'install_python', defaultValue: false, description: 'Check this option to install python packages')
|
|
booleanParam(name: 'refresh_special', defaultValue: false, description: 'When checked the autologin account and kiosk are refreshed only')
|
|
booleanParam(name: 'force_x11', defaultValue: false, description: 'Check this option to force X11 Display Manager')
|
|
|
|
}
|
|
|
|
|
|
|
|
environment {
|
|
ANSIBLE_FORCE_COLOR = '1'
|
|
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')
|
|
}
|
|
|
|
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
|
|
// Also create the kiosk variable yaml with hash value
|
|
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}
|
|
|
|
|
|
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
|
|
kiosk_yaml=/var/jenkins_home/ansible/roles/chrome_kiosk/files/kiosk-\$hash.yaml
|
|
echo --- > \$kiosk_yaml
|
|
echo kiosk_service_templates: >> \$kiosk_yaml
|
|
echo '${params.kiosk_variable}' >> \$kiosk_yaml
|
|
echo ... >> \$kiosk_yaml
|
|
ls -lah /var/jenkins_home/ansible/roles/chrome_kiosk/files/*.yaml
|
|
cat \$kiosk_yaml
|
|
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('Ansible Playbook') {
|
|
steps {
|
|
//Run the cosmos-kiosk ansible playbook
|
|
// /workspace/ansible/playbooks/cosmos-kiosk.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"
|
|
kiosk_yaml=/var/jenkins_home/ansible/roles/chrome_kiosk/files/kiosk-\$hash.yaml
|
|
|
|
cd /var/jenkins_home/ansible
|
|
|
|
ansible-playbook -i \$inventory_file \
|
|
/var/jenkins_home/ansible/playbooks/cosmos-kiosk.yaml --ssh-common-args='-o StrictHostKeyChecking=no' \
|
|
--extra-vars "docker_full=false no_vpn=true jenkins_kiosk=true public_deploy=true \
|
|
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}' \
|
|
new_hostname=${params.new_hostname} force_x11=${params.force_x11} \
|
|
rename_host=${params.rename_endpoint} onboard_pi=${params.onboard_pi} \
|
|
add_domain=${params.add_domain} install_docker=${params.install_docker} \
|
|
install_python=${params.install_python} refresh_special=${params.refresh_special} \
|
|
kiosk_yaml='\$kiosk_yaml'"
|
|
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
always {
|
|
// Remove dynamic Inventory file
|
|
// Remove kiosk_yaml file
|
|
|
|
sh """
|
|
|
|
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
|
|
inventory_file="/var/jenkins_home/ansible/.inv/inventory-\$hash.yml"
|
|
kiosk_yaml=/var/jenkins_home/ansible/roles/chrome_kiosk/files/kiosk-\$hash.yaml
|
|
rm \$inventory_file
|
|
rm \$kiosk_yaml
|
|
|
|
"""
|
|
}
|
|
}
|
|
}
|