diff --git a/Jenkinsfile-v1 b/Jenkinsfile-v1 index cecca85..e05b1d9 100644 --- a/Jenkinsfile-v1 +++ b/Jenkinsfile-v1 @@ -21,6 +21,10 @@ pipeline { } } stage("execute ansible playbook from the ansible-server") { + environment { + AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id') + AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key') + } steps { script { echo "executing ansible-playbook" @@ -35,10 +39,10 @@ pipeline { remote.user = user sshCommand remote: remote, command: "ls -l" - sshCommand remote: remote, command: "apt update" - sshCommand remote: remote, command: "apt install ansible -y" - sshCommand remote: remote, command: "apt install python3-pip -y" - sshCommand remote: remote, command: "pip3 install boto3 botocore" + + // set AWS credentials + sshScript remote: remote, script: "ansible/prepare-server.sh ${AWS_ACCESS_KEY_ID} ${AWS_SECRET_ACCESS_KEY}" + sshCommand remote: remote, command: "ansible-playbook docker-and-compose.yaml" } } diff --git a/ansible/prepare-server.sh b/ansible/prepare-server.sh new file mode 100644 index 0000000..21dcd98 --- /dev/null +++ b/ansible/prepare-server.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +apt update +apt install ansible -y +apt install python3-pip -y +pip3 install boto3 botocore + +export AWS_ACCESS_KEY_ID=$1 +export AWS_SECRET_ACCESS_KEY=$2 + +