-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
387 lines (367 loc) · 10.7 KB
/
index.html
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>reveal.js</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/blood.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/monokai.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section><h4>Ansible: Testing with molecule</h4></section>
<section>
<h5>about us</h5>
<h5>Ansible</h5>
<h5>Testinfra</h5>
<h5>idempotency</h5>
<h5>advanced</h5>
<h5>tipps & tricks</h5>
</section>
<section>
<section>
<h4>Who do we work for?</h4>
<img src="Gdata-by-night-small.jpg" />
</section>
<section>
<h4>Where do we work?</h4>
<img src="Gdata-by-night-small-where.jpg" />
</section>
<section>
<h4>Who we are (shameless plugs at the end)?</h4>
<div class="grid-container" style="display: grid; align-items: center;">
<div class="grid-item" style="grid-column: 1 / span 1;">
<img height="500" src="florian-kuckelkorn.png" style="border-radius: 50%; width: 200px; height: 200px;" />
</div>
<div class="grid-item" style="grid-column: 2 / span 4;">
Florian Kuckelkorn
</div>
<div class="grid-item" style="grid-column: 1 / span 1;">
<img height="500" src="matthias-simonis.jpg" style="border-radius: 50%; width: 200px; height: 200px;" />
</div>
<div class="grid-item" style="grid-column: 2 / span 4;">
Matthias Simonis
</div>
</div>
</section>
<section>
100+ Servers <br /><br />
<ul>
<li>Swarm Nodes</li>
<li>Build Servers</li>
<li>Databases</li>
</ul>
</section>
</section>
<section>
<section>
<h4>Ansible</h4>
</section>
<section>
<ul>
<li>messy playbooks</li>
<li>interconected roles</li>
<li>the fear of running a playbook</li>
<li>configuration drift</li>
</ul>
</section>
<section>
<ul>
<li>reliability</li>
<li>infrastructure as code</li>
<li>a role as a software unit</li>
</ul>
</section>
<section>
<img src="developers-5ti84m.jpg" />
</section>
<section>
<h4>tests</h4>
<ul>
<li>testing role functionality when creating a role</li>
<li>testing role functionality when making changes</li>
</ul>
</section>
</section>
<section>
<section>
<h4>molecule</h4>
</section>
<section>
<h4>Workshop onboarding</h4>
<ul>
<li><a href="https://gitlab.com/devopsgatheringgdata">Gitlab</a></li>
<li>Slack</li>
<li><a href="https://gitlab.com/devopsgatheringgdata/moleculeworkshopstepsslides">slides</a></li>
</ul>
</section>
</section>
<section>
<section>
<h4>Lession 1: Initialize a role and pass a test</h4>
<pre><code data-trim data-noescape>
molecule init role --verifier-name testinfra rolename
</code></pre>
Now add linting and try to get the test to pass
<pre><code data-trim data-noescape>
molecule test --all
</code></pre>
<b>15 Minutes</b>
</section>
<section>
<h4>Just by doing that you get</h4>
<ul>
<li>validation</li>
<li>linting</li>
<li>idempotency check</li>
</ul>
</section>
<section>
<img src="initialized-role.png" />
</section>
</section>
<section>
<section>
<h4>testinfra</h4>
</section>
<section>
molecule/tests/some_test.py
<pre><code data-trim data-noescape>
"""Role testing files using testinfra."""
def test_hosts_file(host):
"""Validate /etc/hosts file."""
f = host.file("/etc/hosts")
assert f.exists
assert f.user == "root"
assert f.group == "root"
</code></pre>
</section>
<section>
<ul>
<li>runs on provisioned machine</li>
<li>check status like file permissions</li>
<li>validate software by running commands</li>
</ul>
</section>
</section>
<section>
<section>
<h4>Lession 2: Add a test to an existing role</h4>
<pre><code data-trim data-noescape>
molecule init scenario --verifier-name testinfra my_new_scenario
</code></pre>
test if the docker-compose flag is working<br />
also add linting to the default test<br />
<b>hint</b>: running docker-compose should fail<br />
<b>hint</b>: the converge.yml is a real playbook<br />
<b>30 Minutes</b>
</section>
<section>
molecule/tests/some_test.py
<pre><code data-trim data-noescape>
"""Role testing files using testinfra."""
def test_docker_compose_working(host):
cmd = host.run('docker-compose --version')
assert cmd.rc != 0
</code></pre>
molecule/converge.yml
<pre><code data-trim data-noescape>
roles:
- role: geerlingguy.docker
vars:
docker_install_compose: false
</code></pre>
</section>
</section>
<section>
<section>
<h4>the key to idempotency: custom facts</h4>
</section>
<section>
files/some_fact.txt
<pre><code data-trim data-noescape>
#!/bin/bash
echo "[ $(docker ps --all --format "{{json .Names}},") ]" | \
sed "s#, ]# ]#g"
</code></pre>
</section>
<section>
tasks/my_task.yml
<pre><code data-trim data-noescape>
- name: "Create custom fact directory"
file:
path: "/etc/ansible/facts.d"
state: "directory"
- name: "Insert custom fact file for docker container"
copy:
src: files/docker_containers.fact
dest: /etc/ansible/facts.d/docker_containers.fact
mode: 0755
- name: reload ansible_local
setup:
filter: ansible_local
</code></pre>
</section>
<section>
tasks/my_task.yml
<pre><code data-trim data-noescape>
- name: "Run platform container (custom)"
command: docker run --rm -d -p 8080:8000 \
--name ptl-whoami jwilder/whoami:latest
when: '"ptl-whoami" not in ansible_local.docker_containers'
</code></pre>
</section>
<section>
<h4>the easy way out</h4>
tasks/my_task.yml
<pre><code data-trim data-noescape>
- name: initialize the swarm
shell: docker swarm init \
--advertise-addr {{ansible_default_ipv4.address}}
when:
- "docker_info.stdout.find('Swarm: inactive') != -1"
- "not hostvars['DOCKER_SWARM_TOKEN_HOLDER']"
</code></pre>
</section>
</section>
<section>
<section>
<h4>Lession 3: Add functionality to a role</h4>
<pre><code data-trim data-noescape>
molecule init scenario --verifier-name testinfra my_new_scenario
</code></pre>
start a container on the server and test if its working<br />
use jwilder/whoami image thats easy to handle<br />
<b>30 Minutes</b>
</section>
<section>
molecule/tests/some_test.py
<pre><code data-trim data-noescape>
"""Role testing files using testinfra."""
def test_docker_compose_working(host):
cmd = host.run('docker-compose --version')
assert cmd.rc != 0
</code></pre>
</section>
</section>
<section>
<section>
<h4>advanced molecule functionality</h4>
</section>
<section>
<h4>dependencies</h4>
meta/main.yml
<pre><code data-trim data-noescape>
dependencies:
- name: geerlingguy.docker
</code></pre>
molecule/requirements.yml
<pre><code data-trim data-noescape>
---
- name: geerlingguy.docker
</code></pre>
</section>
<section>
<h4>advanced inventories</h4>
molecule/converge.yml
<pre><code data-trim data-noescape>
---
- name: Converge
hosts: manager
serial: 1
tasks:
- name: "Include some_role"
include_role:
name: "some_role"
- name: Converge
hosts: worker
serial: 1
tasks:
- name: "Include some_role"
include_role:
name: "some_role"
</code></pre>
</section>
</section>
<section>
<section>
<h4>Lesson 4: repeat lesson 3</h4>
build a role, that just runs the platform container that depends on the docker role
<h5>or</h5>
<h4>Lesson 5: build a docker swarm</h4>
create a role that initializes a docker swarm
hint: <a href="https://github.com/unglaublicherdude/ansible_play_initialize_docker_swarm">Github</a>
</section>
</section>
<section>
<section>
<h4>Tipps & Tricks</h4>
</section>
<section>
<h4>Need debug output from you provisioner?</h4>
molecule/molecule.yml
<pre><code data-trim data-noescape>
provisioner:
name: ansible
log: true
options:
vvv: true
</code></pre>
</section>
</section>
<section>
<h4>Shameless plugs</h4>
<div class="grid-container" style="display: grid; align-items: center;">
<div class="grid-item" style="grid-column: 1 / span 1;">
<img height="500" src="florian-kuckelkorn.png" style="border-radius: 50%; width: 200px; height: 200px;" />
</div>
<div class="grid-item" style="grid-column: 2 / span 4;">
<b>Florian Kuckelkorn</b> <br />
florian.kuckelkorn@gdata.de
</div>
<div class="grid-item" style="grid-column: 1 / span 1;">
<img height="500" src="matthias-simonis.jpg" style="border-radius: 50%; width: 200px; height: 200px;" />
</div>
<div class="grid-item" style="grid-column: 2 / span 4;">
<b>Matthias Simonis</b> <br />
@wirspielen1 <br />
matthias.simonis@gdata.de
</div>
</div>
</section>
<section>
<h4>Shameless plugs 2</h4>
<b>We are hiring!</b>
<img src="Gdata-by-night-small.jpg" />
</section>
</div>
</div>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
hash: true,
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/highlight/highlight.js' },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>