Files
java-maven-app/Jenkinsfile
2021-04-07 11:59:04 +02:00

36 lines
1.4 KiB
Groovy

pipeline {
agent any
stages {
stage("copy files to ansible server") {
steps {
script {
echo "copying all neccessary files to ansible control node"
sshagent(['ansible-server-key']) {
sh "scp -o StrictHostKeyChecking=no ansible/* root@167.99.136.157:/root"
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
sh 'scp $keyfile root@167.99.136.157:/root/ssh-key.pem'
}
}
}
}
}
stage("execute ansible playbook") {
steps {
script {
echo "calling ansible playbook to configure ec2 instances"
def remote = [:]
remote.name = "ansible-server"
remote.host = "167.99.136.157"
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]){
remote.user = user
remote.identityFile = keyfile
sshCommand remote: remote, command: "ansible-playbook my-playbook.yaml"
}
}
}
}
}
}