Created
November 4, 2016 18:19
-
-
Save thomastaylor312/83b188b016188fc2a8d258a27f760120 to your computer and use it in GitHub Desktop.
A population script for creating Kubernetes spec files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -lt 2 ]; then | |
echo 'Expects 2 arguments: ./populate.sh APPLICATION K8S_ENVIRONMENT' | |
exit 1 | |
fi | |
extra_vars="--extra-vars @group_vars/secrets.yml" | |
application=$1 | |
k8s_environment=$2 | |
vault_password_file="${VAULT_PASSWORD_FILE:-./my-vault-stuff/vault-password}" | |
if [ ! -f "${application}.yml" ]; then | |
echo "Could not find expected playbook ${application}.yml" | |
exit 1 | |
else | |
extra_vars="${extra_vars} --extra-vars application=${application}" | |
fi | |
# Make sure the k8s_environment is set | |
if [ "${k8s_environment}" = 'dev' ] || [ "${k8s_environment}" = 'prod' ] || \ | |
[ "${k8s_environment}" = 'staging' ] || [ "${k8s_environment}" = 'test' ]; then | |
extra_vars="${extra_vars} --extra-vars k8s_environment=$k8s_environment" | |
else | |
echo 'You must specify $k8s_environment as dev|prod|staging|test' | |
exit 1 | |
fi | |
if [ -f "group_vars/${application}/${k8s_environment}.yml" ]; then | |
extra_vars="${extra_vars} --extra-vars @group_vars/${application}/${k8s_environment}.yml" | |
else | |
echo "Did not find file: group_vars/${application}/${k8s_environment}.yml" | |
fi | |
if [ -f "group_vars/${k8s_environment}.yml" ]; then | |
extra_vars="${extra_vars} --extra-vars @group_vars/${k8s_environment}.yml" | |
else | |
echo "Did not find file: group_vars/${k8s_environment}.yml" | |
fi | |
# add extra secrets variables if the files exist | |
if [ -f "group_vars/${application}/secrets.yml" ]; then | |
extra_vars="${extra_vars} --extra-vars @group_vars/${application}/secrets.yml" | |
fi | |
if [ -f "group_vars/${application}/secrets/${k8s_environment}.yml" ]; then | |
extra_vars="${extra_vars} --extra-vars @group_vars/${application}/secrets/${k8s_environment}.yml" | |
fi | |
echo "Populating ${application} into environment ${K8S_ENVIRONMENT}" | |
ansible-playbook "${application}.yml" $extra_vars --vault-password-file=$vault_password_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment