-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile.service
85 lines (70 loc) · 3.11 KB
/
justfile.service
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
# Justfile for service actions
# This list of actions
service:
just -l --unsorted | grep service
# Sample calls
service-tldr:
# Sample of calls:
# $ SERVER=yourRemoteServer
#
# $ just service-create traefik $SERVER # Install traefik.
# $ just service-manage traefik $SERVER start # Show the status.
@ echo ""
# > To get a commented list of actions use "just service"
# Shows how to use the script
service-help:
# README SERVICE
@ cat {{ servicePath }}/README.md
@ echo ""
# An alias for "just list service" that shows a full list of service's actions
service-list:
@ just list service
# Creates 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 deault vault in "configs/secrets.yml" with the password stored at .vault.key:
service-vault action:
@ if [[ "${action}" == "create" ]]; then \
echo "${2}" >> ${serviceVaultKey}; \
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
# Runs an action with:
# - Action: Is the playbook name (without .yml) from playbooks/service.
# - 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.
service-run action site host *args:
ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} \
--vault-password-file {{ servicePath }}/{{ vaultKey }} {{ dojoPath }}/{{ action }}.yml \
-e "host={{ host }}" \
-e "site={{ site }}" \
{{ args }}
# Creates a full service acording to the dictionary in inventory/services/<service>.yml
# Following playbooks will be called: create.yml
service-create service host *args:
@ echo "WARNING: Creating a service will overwrite existing one."
@ echo "Are you sure you like to run playbook create.yml \
for [{{ service }}] on [{{ host }}]?" && \
echo 'ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ servicePath }}/{{ vaultKey }} \
{{ servicePath }}/create.yml \
-e "host={{ host }}" \
-e "service={{ service }}" \
-K {{ args }}' && \
ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ servicePath }}/{{ vaultKey }} \
{{ servicePath }}/create.yml \
-e "host={{ host }}" \
-e "service={{ service }}" \
-K {{ args }}
# Manages the service
service-manage service host command *args:
ansible-playbook -i {{ inventoryPath }}/hosts.yml --limit {{ host }} --vault-password-file {{ servicePath }}/{{ vaultKey }} \
{{ servicePath }}/manage.yml \
-e "host={{ host }}" \
-e "service={{ service }}" \
-e "command={{ command }}" \
-K {{ args }}