init commit
This commit is contained in:
63
Jenkinsfile.update-endpoint
Normal file
63
Jenkinsfile.update-endpoint
Normal file
@ -0,0 +1,63 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
// Define parameters
|
||||
parameters {
|
||||
string(name: 'host_ip', description: 'Target System Address')
|
||||
}
|
||||
|
||||
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/update-endpoint.yaml --ssh-common-args='-o StrictHostKeyChecking=no'
|
||||
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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