Repository navigation
Expand file tree
/
Copy pathrefresh
More file actions
executable file
·178 lines (158 loc) · 3.29 KB
/
Copy pathrefresh
File metadata and controls
executable file
·178 lines (158 loc) · 3.29 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
# vi: set sw=4 ts=4 ai:
# Program : refresh
# Author : Ton Kersten
# Date : 03-01-2019
# Refresh the Ansible master directory and
# Install all roles
# Determine the program name and the 'running directory'
IAM="${0##*/}"
CRD="$( [[ "$(printf "${0}" | cut -c 1 )" = "." ]] &&
{ printf "${PWD}/${0}"
} || {
printf "${0}"
})"
CRD="${CRD%/*}"
CUR="${PWD}"
# Define where it all ends up
ANSIBLE_DIR="/etc/ansible"
# Locking mechanism
runs="$(ps -ef | grep '[a]nsible_run')"
if [[ ${runs} == *ansible_run* ]]
then
echo "ansible_run is triggered, please wait!"
exit 1
fi
sleep 1
runs="$(ps -ef | grep '[a]nsible_run')"
if [[ ${runs} == *ansible_run* ]]
then
echo "ansible_run is triggered, please wait!"
exit 1
fi
# Read in the config file
source ${ANSIBLE_DIR}/config ||
{ echo "Could not read config file" >&2
exit 1
}
# Define some constants
T=" "
F=""
GALAXY=0
SETUP=0
DOCS=0
if [[ ( x"${1}" = x"-h" ) || ( x"${1}" = x"--help" ) ]]
then
cat <<- @EOF
Syntax: refresh [-f|--force] [-n|--no-galaxy] [-s|--setup-only] [environment]
${T}-f|--force Force redownload of all roles
${T}-n|--no-galaxy Do not download the Ansible Galaxy roles
${T}-s|--setup-only Only refresh the "setup" master role
${T}-d|--docs-only Only refresh the documentation
${T}environment Only refresh the selected environment
@EOF
exit
fi
if [[ ( x"${1}" = x"-f" ) || ( x"${1}" = x"--force" ) ]]
then
F="--force"
shift
fi
if [[ ( x"${1}" = x"-n" ) || ( x"${1}" = x"--no-galaxy" ) ]]
then
# We should skip downloading from online Ansible Galaxy
GALAXY=1
shift
fi
if [[ ( x"${1}" = x"-s" ) || ( x"${1}" = x"--setup-only" ) ]]
then
SETUP=1
shift
fi
if [[ ( x"${1}" = x"-d" ) || ( x"${1}" = x"--docs-only" ) ]]
then
DOCS=1
shift
fi
# Extra params (for environments)
case "${1:-}"
in
prd) ENVS="prd" ;;
acc) ENVS="acc" ;;
tst) ENVS="tst" ;;
dev) ENVS="dev" ;;
svc) ENVS="prd" ;;
rsc) ENVS="dev" ;;
all) ENVS="dev tst acc prd" ;;
*) ENVS="dev tst acc prd" ;;
esac
cat <<- @EOF
#
# Refreshing setup role
#
@EOF
cd "${ANSIBLE_DIR}"
git pull --force
[[ ${SETUP} -eq 1 ]] && exit 0
# Refresh the documentation
cat <<- @EOF
#
# Refreshing documentation
#
@EOF
if [[ -d "${ANSIBLE_DIR}/docs" ]]
then
cd "${ANSIBLE_DIR}/docs"
git pull --force
cd - > /dev/null
else
git clone ${git_http}/docs.git
fi
[[ ${DOCS} -eq 1 ]] && exit 0
if [[ ${GALAXY} -eq 0 ]]
then
cat <<- @EOF
#
# Installing roles from the Galaxy
#
@EOF
ansible-galaxy install ${F} -p galaxy -r galaxy.yml
echo
fi
for envi in ${ENVS}
do
cat <<- @EOF
#
# Installing roles for "${envi}"
#
@EOF
sed "s/version:.*/version: ${envi}/" roles.yml > /tmp/roles.yml
[[ ! -d roles/${envi} ]] && mkdir -p roles/${envi}
ansible-galaxy install ${F} -p roles/${envi} -r /tmp/roles.yml
echo
done
# For svc (svc is production)
if [[ ${ENVS} == *prd* ]]
then
cat <<- @EOF
#
# Installing roles for "svc"
#
@EOF
[[ -d roles/svc ]] && rm -rf "${ANSIBLE_DIR}/roles/svc"
cp -rp "${ANSIBLE_DIR}/roles/prd" "${ANSIBLE_DIR}/roles/svc"
echo
fi
# For rsc (rsc is development)
if [[ ${ENVS} == *dev* ]]
then
cat <<- @EOF
#
# Installing roles for "rsc"
#
@EOF
[[ -d roles/rsc ]] && rm -rf "${ANSIBLE_DIR}/roles/rsc"
cp -rp "${ANSIBLE_DIR}/roles/dev" "${ANSIBLE_DIR}/roles/rsc"
echo
fi
echo