Newer
Older
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
262
263
264
265
266
267
268
269
---
- name: MOLECULE | Verify
hosts: all
vars:
package_name_docker: 'docker'
package_name_docker_ce: 'docker-ce'
package_name_docker_compose: 'docker-compose'
package_name_docker_compose_plugin: 'docker-compose-plugin'
container_name_cups: 'c3printing-cups'
container_name_app: 'c3printing-app'
container_name_proxy: 'c3printing-proxy'
# container_name_influxdb: 'c3printing-influxdb'
pre_tasks:
- name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../defaults
ansible.builtin.include_vars:
dir: ../../defaults
depth: 1
extensions:
- 'yml'
- name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/c3infodesk-deployment-role-dependencies/defaults
ansible.builtin.include_vars:
dir: ../../../../roles/c3infodesk-deployment-role-dependencies/defaults
depth: 1
extensions:
- 'yml'
- name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/c3infodesk-deployment-role-clone-repositories/defaults
ansible.builtin.include_vars:
dir: ../../../../roles/c3infodesk-deployment-role-clone-repositories/defaults
depth: 1
extensions:
- 'yml'
- name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/c3infodesk-deployment-role-docker-images/defaults
ansible.builtin.include_vars:
dir: ../../../../roles/c3infodesk-deployment-role-docker-images/defaults
depth: 1
extensions:
- 'yml'
# - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/dependencies/defaults
# ansible.builtin.include_vars:
# dir: ../../../../roles/dependencies/defaults
# depth: 1
# extensions:
# - 'yml'
# - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/clone_repositories/defaults
# ansible.builtin.include_vars:
# dir: ../../../../roles/clone_repositories/defaults
# depth: 1
# extensions:
# - 'yml'
# - name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../roles/docker_images/defaults
# ansible.builtin.include_vars:
# dir: ../../../../roles/docker_images/defaults
# depth: 1
# extensions:
# - 'yml'
- name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../inventories/group_vars
ansible.builtin.include_vars:
dir: ../../../../inventories/group_vars
extensions:
- 'yml'
- name: MOLECULE | VERIFY | PRE-TASKS | VARIABLES | From -> ../../../../inventories/host_vars
ansible.builtin.include_vars:
dir: ../../../../inventories/host_vars
extensions:
- 'yml'
tasks:
###
### POPULATE
###
- name: MOLECULE | VERIFY | POPULATE | Gather the package facts
ansible.builtin.package_facts:
manager: auto
- name: MOLECULE | VERIFY | POPULATE | Gather service facts
ansible.builtin.service_facts:
###
### TESTS - PACKAGES
###
- name: MOLECULE | VERIFY | TEST | Check that the packages from 'os_dependencies_packages' are installed.
ansible.builtin.debug:
msg: "Package: '{{ package_name }}' is installed"
loop: "{{ os_dependencies_packages }}"
loop_control:
loop_var: package_name
failed_when: package_name not in ansible_facts.packages
- name: MOLECULE | VERIFY | TEST | Check that docker is installed.
ansible.builtin.debug:
msg: "Package: 'docker' is installed"
failed_when:
- package_name_docker not in ansible_facts.packages
- package_name_docker_ce not in ansible_facts.packages
- name: MOLECULE | VERIFY | TEST | Check that docker-compose is installed.
ansible.builtin.debug:
msg: "Package: 'docker-cokmpose' is installed"
failed_when:
- package_name_docker_compose not in ansible_facts.packages
- package_name_docker_compose_plugin not in ansible_facts.packages
###
### TESTS - DOCKER
###
- name: MOLECULE | VERIFY | TEST | Get docker service state.
ansible.builtin.systemd:
name: "docker"
register: docker_service
- name: MOLECULE | VERIFY | TEST | Check that docker is running.
ansible.builtin.debug:
msg: "Docker IS running..."
failed_when: "'active' != docker_service.status.ActiveState"
###
### TESTS - ADDED USERS
###
- name: MOLECULE | VERIFY | TEST | Get added users infos.
ansible.builtin.user:
name: "{{ item }}"
loop: "{{ docker_users }}"
check_mode: true
register: test_users
- name: MOLECULE | VERIFY | TEST | Check if users exists
ansible.builtin.debug:
msg: "User {{ item.item }} {{ 'exists' if item.state | d('') == 'present' else 'does not exist' }}"
loop: "{{ test_users.results }}"
loop_control:
label: "{{ item.item }}"
- name: MOLECULE | VERIFY | TEST | Get the groups that the users belongs to.
ansible.builtin.command:
cmd: "id -Gn {{ item.item }}"
loop: "{{ test_users.results }}"
loop_control:
label: "{{ item.item }}"
register: user_groups
changed_when: false
- name: MOLECULE | VERIFY | TEST | Check that the users are at the 'docker' group.
ansible.builtin.debug:
msg: "User '{{ item.item.item }}' belongs to the docker group"
with_items: "{{ user_groups.results }}"
failed_when: "'docker' not in item.stdout"
###
### TESTS - CLONE REPOSITORY - PRINTER
###
- name: MOLECULE | VERIFY | TEST | Get if the repository was cloned.
ansible.builtin.git:
repo: "{{ c3infodesk_printer_repo_url }}"
dest: "{{ c3infodesk_printer_folder }}"
version: main
clone: false
update: false
register: check_repository
- name: MOLECULE | VERIFY | TEST | Checking if the repository was cloned.
ansible.builtin.debug:
msg: "Repository: '{{ c3infodesk_printer_repo_url }}' cloned..."
failed_when: check_repository.changed | bool
###
### TESTS - DOCKER IMAGES
###
- name: MOLECULE | VERIFY | TEST | Get if the image is created for 'cups'.
community.docker.docker_image_info:
name: "{{ c3infodesk_printer_docker_img_cups_name }}"
register: result_check_image_cups
- name: MOLECULE | VERIFY | TEST | Check the image creation from 'cups'.
ansible.builtin.debug:
msg: "Image for 'cups' exists"
when: result_check_image_cups.images | length > 0
- name: MOLECULE | VERIFY | TEST | Get if the image is created for 'app'.
community.docker.docker_image_info:
name: "{{ c3infodesk_printer_docker_img_app_name }}"
register: result_check_image_app
- name: MOLECULE | VERIFY | TEST | Check the image creation from 'app'.
ansible.builtin.debug:
msg: "Image for 'app' exists"
when: result_check_image_app.images | length > 0
- name: MOLECULE | VERIFY | TEST | Get if the image is created for 'proxy'.
community.docker.docker_image_info:
name: "{{ c3infodesk_printer_docker_img_proxy_name }}"
register: result_check_image_proxy
- name: MOLECULE | VERIFY | TEST | Check the image creation from 'proxy'.
ansible.builtin.debug:
msg: "Image for 'proxy' exists"
when: result_check_image_proxy.images | length > 0
###
### TESTS - DOCKER CONTAINERS - CUPS DISABLE
###
- name: MOLECULE | VERIFY | TEST | Get that the CUPS service is disable.
ansible.builtin.debug:
msg: "The service: 'cups.service' is not setted"
failed_when: "'cups.service' in ansible_facts.services"
###
### TESTS - DOCKER CONTAINERS - CUPS
###
- name: MOLECULE | VERIFY | TEST | CONTAINER CUPS | Get infos on the container.
community.docker.docker_container_info:
name: "{{ container_name_cups }}"
register: ret_container_cups
- name: MOLECULE | VERIFY | TEST | CONTAINER CUPS | Check that the container exists.
ansible.builtin.debug:
msg: "The container '{{ container_name_cups }}' {{ 'exists' if ret_container_cups.exists else 'does not exist' }}"
failed_when: ret_container_cups.exists | bool is not true
- name: MOLECULE | VERIFY | TEST | CONTAINER CUPS | Check that the container is running.
ansible.builtin.debug:
msg: "The container '{{ container_name_cups }}' is running"
failed_when: ret_container_cups.container.State.Status != 'running'
###
### TESTS - DOCKER CONTAINERS - APP
###
- name: MOLECULE | VERIFY | TEST | CONTAINER APP | Get infos on the container.
community.docker.docker_container_info:
name: "{{ container_name_app }}"
register: ret_container_app
- name: MOLECULE | VERIFY | TEST | CONTAINER APP | Check that the container exists.
ansible.builtin.debug:
msg: "The container '{{ container_name_app }}' {{ 'exists' if ret_container_app.exists else 'does not exist' }}"
failed_when: ret_container_app.exists | bool is not true
- name: MOLECULE | VERIFY | TEST | CONTAINER APP | Check that the container is running.
ansible.builtin.debug:
msg: "The container '{{ container_name_app }}' is running"
failed_when: ret_container_app.container.State.Status != 'running'
###
### TESTS - DOCKER CONTAINERS - PROXY
###
- name: MOLECULE | VERIFY | TEST | CONTAINER PROXY | Get infos on the container.
community.docker.docker_container_info:
name: "{{ container_name_proxy }}"
register: ret_container_proxy
- name: MOLECULE | VERIFY | TEST | CONTAINER PROXY | Check that the container exists.
ansible.builtin.debug:
msg: "The container '{{ container_name_proxy }}' {{ 'exists' if ret_container_proxy.exists else 'does not exist' }}"
failed_when: ret_container_proxy.exists | bool is not true
- name: MOLECULE | VERIFY | TEST | CONTAINER PROXY | Check that the container is running.
ansible.builtin.debug:
msg: "The container '{{ container_name_proxy }}' is running"
failed_when: ret_container_proxy.container.State.Status != 'running'