-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile.dojo
261 lines (228 loc) · 11.5 KB
/
justfile.dojo
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# Justfile for dojo actions
# This list of actions
dojo:
@ just -l --unsorted | grep dojo
# Sample calls
dojo-tldr:
# Sample of calls:
@ echo ""
# $ just dojo-help # Just in case you like to read
# $ just list dojo # For a detailed list of actions
# $ just dojo-run create-journal $JOURNAL $SERVER # Get a full OJS installed (define vars first)
# $ just dojo-run config $JOURNAL $SERVER # Creates a config.inc.php for journalName in the remoteServer.
# $ just dojo-run config.php $JOURNAL $SERVER # Creates a php.custom.ini for journalName in the remoteServer.
# $ just dojo-manage $JOURNAL $SERVER restart # Creates a php.custom.ini for journalName in the remoteServer.
@ # TBD: $ dojo backup $JOURNAL # Backup a full journal
@ # TBD: $ dojo clone $JOURNAL journalclone # Clone a journal
@ # TBD: $ dojo upgrade journalclone 3.4.0-6 # Upgrade a journal to the s
@ # TBD: $ dojo start journalclone # Starts a journal
@ # TBD: $ dojo stop journalclone # Stop a journal
@ # TBD: $ dojo frozen journalclone # Makes a journal work in read-only mode.
@ echo ""
# To get a commented list of actions use "just dojo"
# For a detailed list of actions use "just dojo-list"
# Shows how to use the script
dojo-help:
# README for PKP's dojo playbooks
@ cat {{ dojoPath }}/README.md
@ echo ""
# An alias for "just list dojo" that shows a full list of dojo's actions
dojo-list:
@ just list dojo
# TODO: Creates an manages an ansible vault with default. Actions are:
# - create: Vault is saved at "configs/secrets.yml" with the password passed and stored at .vault.key (check your permissions).
# - edit: Edits the default vault in "configs/secrets.yml" with the password stored at .vault.key:
#
# Manages the ansible vault.
# dojo-vault action:
# @ if [[ "${action}" == "create" ]]; then \
# echo "${2}" >> ${vaultKey}; \
# ansible-vault create --vault-password-file=${vaultKey} ${vaultPath}; \
# elif [[ "${create}" == "edit" ]]; then \
# ansible-vault edit --vault-password-file={{ vaultKey }} {{ vaultPath }}; \
# else \
# echo "Unknown action"; \
# fi
dojo-vault action:
#!/usr/bin/env bash
echo "Action: {{ action }}";
echo "vaultKey: {{ vaultKey }}";
echo "vaultPath: {{ vaultPath }}";
case "{{ action }}" in
"create")
echo "${2}" >> {{ vaultKey }};
ansible-vault create --vault-password-file={{ vaultKey }} {{ vaultPath }};
;;
"edit")
ansible-vault edit --vault-password-file={{ vaultKey }} {{ vaultPath }};
;;
"view")
ansible-vault view --vault-password-file={{ vaultKey }} {{ vaultPath }};
;;
*)
echo "Unknown action";
exit 1;
;;
esac
# DEPRECATED: Create a config.inc.php based on the specified dictionary name (ie: periodicum). Vault need to be created first.
# Crea un fichero en "/tmp/>name>.config.inc.php" con la plantilla de /templates/<site>.yml y las variables del diccionario "/sites/<name>.yml"
_dojo-site-old action name:
#!/usr/bin/env sh
echo "{{ action }} - {{ name }}"
# case ${action} in
# create-config)
# ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ name }} --vault-password-file {{ vaultKey }} ./config.yml -e "site={{ name }}"
# ;;
# create-all)
# echo "Create ALL: {{ action }} - {{ name }}"
# ;;
# esac
# Runs an action with:
# - Action: Is the playbook name (without .yml) from playbooks/dojo.
# - Site: A "site" is an ansible dictionary read from inventory/sites.
# - Host: A "host" Acording to the inverntory/hosts.yml
# - Args: Additional arguments.
#
# Runs an action (playbook) with the specified site (dictionary) in the selected host.
dojo-run action site host *args:
ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ dojoPath }}/{{ vaultKey }} {{ dojoPath }}/{{ action }}.yml \
-e "host={{ host }}" \
-e "site={{ site }}" \
-e "ansible_become_password=$(cat ./configs/{{ host }}.vault.key)" \
{{ args }}
# Runs the specified action against all the sites from "siteList" file, acording to the dictionaries in sites/<site>.yml
# Detailed output will be stored in a log file.
# If you only like to run once, you can do it calling "dojo-run" playbook.
# IMPORTANT: Sudo password won't be requested (it's taken from configs/{hostname}.vault.key).
dojo-batch-run siteList host action *args:
#!/usr/bin/env sh
# Path to store the detailed log:
logFile="logs/$(date +'%Y%m%d-%H%M')_{{ host }}-batch_{{ action }}.log";
totalStart=$(date +%s);
# Show the action and asks for confirmation
echo '=====================================================================================';
echo 'SERVER: {{ host }}';
echo 'ACTION: {{ action }}';
echo 'ARGS: {{ args }}';
echo 'SITELIST: {{ siteList }}';
echo "LOGS: $logFile";
echo '=====================================================================================';
echo '';
echo 'WARNING: Some actions could be destructive.';
read -p 'Are you sure you like to run this batch process? [y/N] ' confirm;
echo '';
if [ ${confirm:-no} = 'y' ]; then
while IFS= read -r site; do
siteStart=$(date +%s);
echo "";
echo "-----------------------------------------------";
echo "---> SITE: $site";
# echo "DEBUG COMMAND:";
# echo "ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ dojoPath }}/{{ vaultKey }} \
# {{ dojoPath }}/{{ action }}.yml \
# -e \"host={{ host }}\" \
# -e \"site=$site ansible_become_password=[./configs/{{ host }}.vault.key]\" \
# {{ args }}";
ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ dojoPath }}/{{ vaultKey }} \
{{ dojoPath }}/{{ action }}.yml \
-e "host={{ host }}" \
-e "site=$site" \
-e "ansible_become_password=$(cat ./configs/{{ host }}.vault.key)" \
{{ args }} >> $logFile 2>&1;
siteEnd=$(date +%s);
siteDuration=$(( siteEnd - siteStart ));
echo "Completed in $siteDuration seconds.";
echo "-----------------------------------------------";
done < {{ siteList }};
totalEnd=$(date +%s);
totalDuration=$(( totalEnd - totalStart ));
echo '';
echo '=====================================================================================';
echo "Batch process completed in $totalDuration seconds.";
echo "Full logs at: $logFile";
echo '=====================================================================================';
else
echo "EXIT: Well done! A coward is good for two battles.";
fi
# Creates a full site with acording to the dictionary in sites/<site>.yml
# Following playbooks will be called: site-folders > config > db > apache > docker-compose
#
# Multiplaybook: Creates a full site acording to the site's dictionary.
dojo-create site host *args:
@ echo 'This will run playbooks: site-folders > config > db > apache > docker-compose > env > permissions.'
@ echo "WARNING: Creating a site will overwrite data in the existing one!!"
@ echo "Are you sure you like to run action "create" for [{{ site }}] on [{{ host }} - `dig +short {{ host }}`]?"
@ ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ dojoPath }}/{{ vaultKey }} \
{{ dojoPath }}/site-folders.yml \
{{ dojoPath }}/config.yml \
{{ dojoPath }}/config.db.yml \
{{ dojoPath }}/config.php.yml \
{{ dojoPath }}/docker-compose.yml \
{{ dojoPath }}/apache.yml \
{{ dojoPath }}/env.yml \
{{ dojoPath }}/permissions.yml \
-e "host={{ host }}" \
-e "site={{ site }}" \
-e "ansible_become_password=$(cat ./configs/{{ host }}.vault.key)" \
-K {{ args }}
# Creates or recreates all the sites from "siteList" file, acording to the dictionaries in sites/<site>.yml
# Script also calls sync-ugrade at the end to ensure data is sync and OJS is upgraded to last version.
# Files will be overwiten
# If you only like to run once, you can do it calling "dojo-create" job and "sync-upgrade" playbook.
# IMPORTANT: Sudo password won't be requested (it's taken from configs/{hostname}.vault.key).
#
# Multiplaybook: Creates or recreates all sites listed in "siteList".
dojo-batch-create-ugrade siteList host *args:
@ echo 'This will run playbooks: site-folders > config > db > apache > docker-compose > env > permissions > sync-ugrade.'
@ echo "WARNING: Creating sites will overwrite data for the existing one!!"
@ read -p "Are you sure you like to run action "create" for ALL SITES in [{{ siteList }}] on [{{ host }} - `dig +short {{ host }}`]? [y/N] " confirm; \
if [ ${confirm:-no} = 'y' ]; then \
while IFS= read -r site; do \
echo ""; \
echo "==============================================="; \
echo "---> BUILDING SITE: $site"; \
echo "==============================================="; \
echo "COMMAND:"; \
echo "ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ dojoPath }}/{{ vaultKey }} \
{{ dojoPath }}/site-folders.yml \
{{ dojoPath }}/config.yml \
{{ dojoPath }}/config.db.yml \
{{ dojoPath }}/config.php.yml \
{{ dojoPath }}/docker-compose.yml \
{{ dojoPath }}/apache.yml \
{{ dojoPath }}/env.yml \
{{ dojoPath }}/permissions.yml \
{{ dojoPath }}/sync-upgrade.yml \
-e "host={{ host }}" \
-e \"site=$site ansible_become_password=[./configs/{{ host }}.vault.key]\" \
{{ args }}"; \
echo "LOG:"; \
ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ dojoPath }}/{{ vaultKey }} \
{{ dojoPath }}/site-folders.yml \
{{ dojoPath }}/config.yml \
{{ dojoPath }}/config.db.yml \
{{ dojoPath }}/config.php.yml \
{{ dojoPath }}/docker-compose.yml \
{{ dojoPath }}/apache.yml \
{{ dojoPath }}/env.yml \
{{ dojoPath }}/permissions.yml \
{{ dojoPath }}/sync-upgrade.yml \
-e "host={{ host }}" \
-e "site=$site" \
-e "ansible_become_password=$(cat ./configs/{{ host }}.vault.key)" \
{{ args }}; \
done < {{ siteList }}; \
else \
echo "EXIT: Well done! A coward is good for two battles."; \
fi
#fi 2>&1 | tee -i -a batchCreation.log;
#
# Manages the site
dojo-manage site host command *args:
ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ dojoPath }}/{{ vaultKey }} \
{{ dojoPath }}/manage.yml \
-e "host={{ host }}" \
-e "site={{ site }}" \
-e "ansible_become_password=$(cat ./configs/{{ host }}.vault.key)" \
-e "command={{ command }}" \
{{ args }}