66 lines
1.8 KiB
Plaintext
66 lines
1.8 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
// Define parameters
|
|
parameters {
|
|
string(name: 'host_ip', description: 'Target System Address')
|
|
text(name: 'vpn_config', defaultValue: 'Paste entire config here', description: 'OpenVPN Config')
|
|
}
|
|
|
|
environment {
|
|
ANSIBLE_FORCE_COLOR = '1'
|
|
}
|
|
|
|
options {
|
|
ansiColor('xterm')
|
|
}
|
|
|
|
stages {
|
|
|
|
|
|
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/wrt/nordvpn.yaml --ssh-common-args='-o StrictHostKeyChecking=no' \
|
|
--extra-vars "new_hostname=${params.new_hostname} vpn_config=${params.vpn_config}"
|
|
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
"""
|
|
}
|
|
}
|
|
|
|
}
|