-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.sh
executable file
·50 lines (43 loc) · 2.03 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# TODO: read args for more ansible vars
# Expect env vars: aws_region, aws_RO_accounts, image_name, namespace
export ANSIBLE_ROLES_PATH=$(pwd)/roles:/etc/ansible/roles
export python=$(which python)
if [ -n "${aws_region}" ]; then
export AWS_DEFAULT_REGION=${aws_region}
#arg_region="--extra-vars aws_region=${aws_region}"
fi
#if [ -n "${aws_RO_accounts}" ]; then
# accounts_quoted="\"${aws_RO_accounts//,/\",\"}\""
# arg_accounts="--extra-vars '{\"aws_RO_accounts\":[${accounts_quoted}]}'"
# #arg_accounts="--extra-vars='{\"aws_RO_accounts\":[${aws_RO_accounts}]}'"
#fi
#if [ -n "${image_name}" ]; then
# arg_image="--extra-vars image_name=${image_name}"
#fi
#if [ -n "${namespace}" ]; then
# arg_namespace="--extra-vars namespace=${namespace}"
#fi
accounts_quoted="\"${aws_RO_accounts//,/\",\"}\""
#json="'{\"aws_region\":\"${aws_region}\",\"image_name\":\"${image_name}\",\"namespace\":\"${namespace}\",\"aws_RO_accounts\":[${accounts_quoted}]}'"
echo "{\"aws_region\":\"${aws_region}\",\"image_name\":\"${image_name}\",\"namespace\":\"${namespace}\",\"aws_RO_accounts\":[${accounts_quoted}]}" > run_vars.json
env | sort | grep -v ^LESS_TERMCAP
echo -e "\nInstall: pip modules..."
pip install -r requirements.txt
echo -e "\nVersions"
ansible --version
docker --version
echo -e "\nInstall: Ansible roles..."
ansible-galaxy install -f -r requirements.yml
echo -e "\nTest: syntax"
ansible-playbook -i inventory playbook.yml --syntax-check --list-tasks
echo -e "\nTest: Lint"
ansible-lint -x ANSIBLE0012,ANSIBLE0013 playbook.yml
echo -e "\nRun: playbook"
# Only passing simple vars or json as a file works
echo "CMD: ansible-playbook -i inventory playbook.yml --extra-vars ansible_python_interpreter=${python} -vvvv \
--extra-vars \"@run_vars.json\""
# ${arg_region} ${arg_image} ${arg_namespace} ${arg_accounts}"
ansible-playbook -i inventory playbook.yml --extra-vars ansible_python_interpreter=${python} -vvvv \
--extra-vars "@run_vars.json"
# --extra-vars ${json} # No errors, but not used
# ${arg_region} ${arg_image} ${arg_namespace} ${arg_accounts}