forked from dresden-weekly/vagrant-ansible-remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.sh
executable file
·68 lines (59 loc) · 2.1 KB
/
remote.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
set -e
# configuration options
# =====================
#
# PROJECT_FOLDER (default: "$(pwd)")
# Absolute path of the Project (containing the Vagrantfile)
# VAGRANT_ANSIBLE_REMOTE (default: "vagrant_ansible_remote")
# Relative path of vagrant-ansible-remote to the project
# ANSIBLE_PROJECT_FOLDER (default: "$PROJECT_FOLDER/ansible")
# absolute base folder for the default ansible folders
# VAGRANT_INVOKED (default: false)
# flag whether this script was invoked through Vagrant
# inhibits recursive invokation
# --- option defaults ---
PROJECT_FOLDER=${PROJECT_FOLDER:=$(pwd)}
VAGRANT_ANSIBLE_REMOTE=${VAGRANT_ANSIBLE_REMOTE:=vagrant_ansible_remote}
ANSIBLE_PROJECT_FOLDER=${ANSIBLE_PROJECT_FOLDER:=$PROJECT_FOLDER/ansible}
VAGRANT_INVOKED=${VAGRANT_INVOKED:=false}
# --- contstants ---
RED='\033[0;31m'
NORMAL='\033[0m'
# --- check environment ---
if [ -z "$PROJECT_FOLDER" ] || [ ! -d "$PROJECT_FOLDER" ]; then
echo -e "${RED}PROJECT_FOLDER is not valid${NORMAL}"
exit 20
fi
if [ -z "$VAGRANT_ANSIBLE_REMOTE" ] || [ ! -d "$PROJECT_FOLDER/$VAGRANT_ANSIBLE_REMOTE" ]; then
echo -e "${RED}VAGRANT_ANSIBLE_REMOTE is not valid${NORMAL}"
exit 21
fi
# --- resolve arguments ---
source $PROJECT_FOLDER/$VAGRANT_ANSIBLE_REMOTE/ansible/run-args.sh
# --- vagrant invocation ---
if [ ! "$VAGRANT_INVOKED" == true ] && [ "$ANSIBLE_RUN_VAGRANT" == true ]; then
source $PROJECT_FOLDER/$VAGRANT_ANSIBLE_REMOTE/vagrant/ssh-ansible.sh
exit 0
fi
# --- ansible installation ---
if [ -s "$PROJECT_FOLDER/ansible/install.sh" ]; then
source $PROJECT_FOLDER/ansible/install.sh
else
source $PROJECT_FOLDER/$VAGRANT_ANSIBLE_REMOTE/ansible/git-install.sh
fi
# --- ansible-vault invocation ---
if [ "$ANSIBLE_RUN_VAULT" == true ]; then
if [ -s "$PROJECT_FOLDER/ansible/vault.sh" ]; then
source $PROJECT_FOLDER/ansible/vault.sh
else
source $PROJECT_FOLDER/$VAGRANT_ANSIBLE_REMOTE/ansible/vault.sh
fi
exit 0
fi
# --- ansible-playbook invocation ---
if [ -s "$PROJECT_FOLDER/ansible/run.sh" ]; then
source $PROJECT_FOLDER/ansible/run.sh
else
source $PROJECT_FOLDER/$VAGRANT_ANSIBLE_REMOTE/ansible/run.sh
fi