43 lines
1.7 KiB
Plaintext
43 lines
1.7 KiB
Plaintext
pipeline {
|
|
agent any
|
|
environment {
|
|
ANSIBLE_SERVER = "157.230.120.252"
|
|
}
|
|
stages {
|
|
stage("copy ansible folder and ec2 access key to ansible-server") {
|
|
steps {
|
|
script {
|
|
sshagent(['ansible-server-key']) {
|
|
echo "copying ansible folder to ansible server"
|
|
// ${ANSIBLE_SERVER}:/root without root will give jenkins@${ANSIBLE_SERVER}:/root
|
|
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
|
|
|
|
echo "copying ssh keys for ec2 instances"
|
|
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
|
|
sh "scp ${keyfile} root@${ANSIBLE_SERVER}:/root/key.pem"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage("execute ansible playbook from the ansible-server") {
|
|
steps {
|
|
script {
|
|
echo "executing ansible-playbook"
|
|
|
|
def remote = [:]
|
|
remote.name = "ansible-server"
|
|
remote.host = ANSIBLE_SERVER
|
|
remote.allowAnyHosts = true
|
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
|
|
remote.identityFile = keyfile
|
|
remote.user = user
|
|
|
|
sshCommand remote: remote, command: "ls -l"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |