Add copying ssh key for ec2
This commit is contained in:
@@ -4,22 +4,19 @@ pipeline {
|
|||||||
ANSIBLE_SERVER = "157.230.120.252"
|
ANSIBLE_SERVER = "157.230.120.252"
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage("copy playbook to ansible-server") {
|
stage("copy ansible folder and ec2 access key to ansible-server") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "copying ansible folder to ansible server"
|
|
||||||
sshagent(['ansible-server-key']) {
|
sshagent(['ansible-server-key']) {
|
||||||
|
echo "copying ansible folder to ansible server"
|
||||||
// ${ANSIBLE_SERVER}:/root without root will give jenkins@${ANSIBLE_SERVER}:/root
|
// ${ANSIBLE_SERVER}:/root without root will give jenkins@${ANSIBLE_SERVER}:/root
|
||||||
sh "scp -o StrictHostKeyChecking=no ansible/ansible.cfg root@${ANSIBLE_SERVER}:/root"
|
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage("copy ssh keys for Ansible") {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "copying ssh keys for ec2 instances"
|
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,8 +30,8 @@ pipeline {
|
|||||||
remote.host = ANSIBLE_SERVER
|
remote.host = ANSIBLE_SERVER
|
||||||
remote.allowAnyHosts = true
|
remote.allowAnyHosts = true
|
||||||
|
|
||||||
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'identity', usernameVariable: 'user')]) {
|
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
|
||||||
remote.identityFile = identity
|
remote.identityFile = keyfile
|
||||||
remote.user = user
|
remote.user = user
|
||||||
|
|
||||||
sshCommand remote: remote, command: "ls -l"
|
sshCommand remote: remote, command: "ls -l"
|
||||||
|
|||||||
Reference in New Issue
Block a user