Skip to content

Instantly share code, notes, and snippets.

@sanjayginde
Created September 4, 2019 23:18
Show Gist options
  • Save sanjayginde/37d585c9743235d67ad383db027baba7 to your computer and use it in GitHub Desktop.
Save sanjayginde/37d585c9743235d67ad383db027baba7 to your computer and use it in GitHub Desktop.
Ansible deploy via docker
#!/bin/bash -e
if [ -z "$KEY_DIR" ]; then
echo "FAILED: \$KEY_DIR is required. Please point it at the location of your identity keys."
exit 1
fi
# if [ -z "$AWS_ACCESS_KEY_ID" ]; then
# echo "FAILED: \$AWS_ACCESS_KEY_ID is required. Please pass this variable inline or export to your session."
# exit 1
# fi
# if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
# echo "FAILED: \$AWS_SECRET_ACCESS_KEY is required. Please pass this variable inline or export to your session."
# exit 1
# fi
if [ -z "$AWS_PROFILE" ]; then
echo "FAILED: \$AWS_PROFILE is required. Please pass this variable inline or export to your session."
exit 1
fi
case "$1" in
qa)
docker run \
-v $KEY_DIR/:/root/.ssh/ \
-v ~/.aws:/root/.aws \
-v $(pwd):/home/ \
-e AWS_PROFILE=$AWS_PROFILE \
-it \
727712672144.dkr.ecr.us-east-1.amazonaws.com/contently/ansible:latest \
/bin/sh \
-c "cd /home && ansible-playbook -v -i hosts/qa/inventory.ini configure/domain_proxy.yml --extra-vars \"state=running\""
;;
staging)
docker run \
-v $KEY_DIR/:/root/.ssh/ \
-v $(pwd):/home/ \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-it \
727712672144.dkr.ecr.us-east-1.amazonaws.com/contently/ansible:latest \
/bin/sh \
-c "cd /home && ansible-playbook -v -i hosts/staging/inventory.ini action/deploy_domain_proxy.yml"
;;
prod)
docker run \
-v $KEY_DIR/:/root/.ssh/ \
-v $(pwd):/home/ \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-it \
727712672144.dkr.ecr.us-east-1.amazonaws.com/contently/ansible:latest \
/bin/sh \
-c "cd /home && ansible-playbook -v -i hosts/production/inventory.ini action/deploy_domain_proxy.yml"
;;
*)
echo "FAILED: The environment \"${1}\" is not supported"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment