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 { pipeline {
agent any agent any
environment {
ANSIBLE_SERVER = "167.99.136.157"
}
stages { stages {
stage("copy files to ansible server") { stage("copy files to ansible server") {
steps { steps {
script { script {
echo "copying all neccessary files to ansible control node" echo "copying all neccessary files to ansible control node"
sshagent(['ansible-server-key']) { 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')]) { 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" echo "calling ansible playbook to configure ec2 instances"
def remote = [:] def remote = [:]
remote.name = "ansible-server" remote.name = "ansible-server"
remote.host = "167.99.136.157" remote.host = ANSIBLE_SERVER
remote.allowAnyHosts = true remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]){ withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]){