Hi,
I want to execute a script over a jenkins pipline
here is the snippet
def outputVyos2 = sh(script: "sshpass -p ${pass} ssh -o StrictHostKeyChecking=no ${user}@${params.VyosHostname2} '/bin/vbash -c \"source /opt/vyatta/etc/functions/script-template; /config/scripts/vrrp.sh\"'", returnStdout: true).trim()
I got no output, any idea whats wrong?
Yesterday I did the same and came across the way you showed it didn’t work. What did work for me was (as mentioned in another thread by a/the developer ):
ssh <remote host> "/opt/vyatta/bin/vyatta-op-cmd-wrapper show vrrp"
Name Interface VRID State Priority Last Transition
------ ----------- ------ ------- ---------- -----------------
int eth1 1 MASTER 200 6h53m
public eth0 102 MASTER 200 6h53m
Maybe you can got the information with api
curl -k --location --request POST 'https://vyos/show' \
--form data='{"op": "show", "path": ["vrrp“]}' \
--form key='MY-HTTPS-API-PLAINTEXT-KEY'
1 Like
Hi,
I have removed my def definition, now it works.
stage ('Prepare and Execute VRRP Check') {
withCredentials([usernamePassword(credentialsId: 'vyossetuppass', passwordVariable: 'pass', usernameVariable: 'user')]) {
sh "sshpass -p ${pass} ssh -o StrictHostKeyChecking=no ${user}@${params.VyosHostname2} '/bin/vbash /config/scripts/vrrp.sh'"
sh "sshpass -p ${pass} ssh -o StrictHostKeyChecking=no ${user}@${params.VyosHostname3} '/bin/vbash /config/scripts/vrrp.sh'"
}
}
}
Here is my jenkinsfile to check if both vyos are running correct with show vrrp
I use the API, ssh is a bit tricky with ssh fingerprints
node('vyos-check') {
properties([
parameters([
string(name: 'VyosHostname2', defaultValue: 'vyos02.com', description: 'Hostname of the first VyOS Vyos'),
string(name: 'VyosHostname3', defaultValue: 'vyos03.com', description: 'Hostname of the second VyOS Vyos'),
string(name: 'ApiDeployKey', defaultValue: '12345666666', description: 'API Deploy Key')
])
])
stage('Check VRRP Status') {
script {
env.VYOS_API_ENDPOINT1 = "https://${params.VyosHostname2}/show"
env.VYOS_API_ENDPOINT2 = "https://${params.VyosHostname3}/show"
def response1 = sh(script: "curl -k --location --request POST '${VYOS_API_ENDPOINT1}' --form data='{\"op\": \"show\", \"path\": [\"vrrp\"]}' --form key='${params.ApiDeployKey}'", returnStdout: true).trim()
def response2 = sh(script: "curl -k --location --request POST '${VYOS_API_ENDPOINT2}' --form data='{\"op\": \"show\", \"path\": [\"vrrp\"]}' --form key='${params.ApiDeployKey}'", returnStdout: true).trim()
// Assume you have logic to parse responses and determine if the setup is correct
// This is a placeholder for your actual comparison logic
echo "Response from ${params.VyosHostname2}: ${response1}"
echo "Response from ${params.VyosHostname3}: ${response2}"
// Placeholder comparison logic
if (response1.contains("MASTER") && response2.contains("BACKUP")) {
echo 'VRRP setup is correct.'
} else if (response1.contains("BACKUP") && response2.contains("MASTER")) {
echo 'VRRP setup is correct.'
} else {
error 'VRRP setup is incorrect.'
}
}
}
}
system
Closed
March 7, 2024, 10:35am
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.