-
Notifications
You must be signed in to change notification settings - Fork 8
/
playbook.yml
84 lines (74 loc) · 2.81 KB
/
playbook.yml
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
---
- name: Install lokal
hosts: all
roles:
- lokal
tasks:
- name: Install all services
loop: "{{['base', ] + services}}"
loop_control:
loop_var: service
include_role:
name: "{{service}}"
tasks_from: "main"
when: '(not install is defined and not remove is defined and not backup is defined and not restore is defined) or (install is defined and install == "all")'
- name: Check selected service is listed in services variable
ansible.builtin.fail:
msg: "Services to install: {{install}} are not defined in services variable: {{services}}"
when: "install is defined and install|split(',')|difference(['base', ] + services) is truthy"
- name: Install specified services
loop: "{{ install | split(',') }}"
loop_control:
loop_var: service
include_role:
name: "{{service}}"
tasks_from: "main"
when: "install is defined and install|split(',')|difference(['base', ] + services) is falsy"
- name: Check selected services for backup were installed
ansible.builtin.fail:
msg: "Services to backup: {{backup}} are not defined in services variable: {{services}}"
when: "backup is defined and backup != 'all' and backup|split(',')|difference(services) is truthy"
- name: Backup specified services
loop: "{{ backup | split(',') }}"
loop_control:
loop_var: service
include_role:
name: "{{service}}"
tasks_from: "backup"
when: "backup is defined and backup != 'all' and backup|split(',')|difference(services) is falsy"
- name: Backup all services
when: backup is defined and backup == 'all'
loop: "{{['base', ] + services}}"
loop_control:
loop_var: service
include_role:
name: "{{service}}"
tasks_from: "backup"
- name: Check selected services for restore were at least installed
ansible.builtin.fail:
msg: "Services to restore: {{restore}} are not defined in services variable: {{services}}"
when: "restore is defined and restore != 'all' and restore|split(',')|difference(services) is truthy"
- name: Restore specified services
loop: "{{ restore | split(',') }}"
loop_control:
loop_var: service
include_role:
name: "{{service}}"
tasks_from: "restore"
when: "restore is defined and restore != 'all' and restore|split(',')|difference(services) is falsy"
- name: Restore all services
loop: "{{['base', ] + services}}"
loop_control:
loop_var: service
include_role:
name: "{{service}}"
tasks_from: "restore"
when: "restore is defined and restore == 'all'"
- name: Remove services
loop: "{{ remove | split(',') }}"
loop_control:
loop_var: service
include_role:
name: "{{service}}"
tasks_from: "remove"
when: "remove is defined and remove|split(',')|difference(services) is falsy"