-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathansible.sh
46 lines (34 loc) · 975 Bytes
/
ansible.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
#!/bin/bash
# Run Ansible
cd $(dirname $0) && set -e
if [ -f env.sh ]; then
for var in $(cat env.sh); do
if ! echo "$var" | grep "^#" >/dev/null; then
export "$var"
fi
done
fi
if [ -f 'ansible/bin/activate' ]; then source ansible/bin/activate; fi
# Run playbook
if python3 -m ansible doc -h >/dev/null; then
ansible_eval="python3 -m ansible playbook"
if [ "$ANSIBLE_VAULT" != "" ]; then
echo '#!/bin/bash' > vault-secret
echo "echo $ANSIBLE_VAULT" >> vault-secret
chmod 700 vault-secret
ansible_eval="${ansible_eval} --vault-password-file vault-secret"
fi
if [ -f env.yml ]; then
ansible_eval="${ansible_eval} -e @env.yml"
fi
if [ -d inventory ]; then
ansible_eval="${ansible_eval} -i inventory"
elif [ -f inventory.yaml ]; then
ansible_eval="${ansible_eval} -i inventory.yaml"
fi
ansible_eval="${ansible_eval} ${@}"
set -x
exec $ansible_eval
else
echo "ansible not found. please install."
fi