Create ansible server env var

This commit is contained in:
Nana Janashia
2021-04-07 12:04:09 +02:00
parent 3208a0e63e
commit 3b6780360c

9
Jenkinsfile vendored
View File

@@ -1,15 +1,18 @@
pipeline {
agent any
environment {
ANSIBLE_SERVER = "167.99.136.157"
}
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"
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
sh 'scp $keyfile root@167.99.136.157:/root/ssh-key.pem'
sh 'scp $keyfile root@$ANSIBLE_SERVER:/root/ssh-key.pem'
}
}
}
@@ -21,7 +24,7 @@ pipeline {
echo "calling ansible playbook to configure ec2 instances"
def remote = [:]
remote.name = "ansible-server"
remote.host = "167.99.136.157"
remote.host = ANSIBLE_SERVER
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]){