@@ -207,7 +207,17 @@ so once you've set up your A-record,
207
207
you can check its progress on a "propagation checking" service like this one:
208
208
https://www.whatsmydns.net/#A/staging.ottg.co.uk.
209
209
210
- I'm planning to host my staging server at 'staging.ottg.co.uk':
210
+ I'm planning to host my staging server at _staging.ottg.co.uk_
211
+
212
+ === Installing ansible
213
+
214
+ TODO:
215
+
216
+ https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
217
+
218
+ suggests pipx. could also install it in the local virtualenv?
219
+ may need to add docker-sdk
220
+
211
221
212
222
213
223
=== A first Cut of an Ansible Script
@@ -242,7 +252,6 @@ The "hate" part is that the actual syntax is surprisingly fiddly to get right:
242
252
the difference between lists and key/value maps is subtle and I can never quite remember it honestly.]
243
253
relationship with.
244
254
245
- TODO: forget podman, just use docker.
246
255
247
256
[role="sourcecode"]
248
257
.infra/ansible-provision.yaml (ch11l001)
@@ -289,6 +298,7 @@ TODO: forget podman, just use docker.
289
298
state: started
290
299
image: busybox
291
300
command: echo hello world
301
+ become: true
292
302
----
293
303
====
294
304
@@ -301,28 +311,87 @@ TODO: forget podman, just use docker.
301
311
The next few use the `builtin.apt` module which provides
302
312
a wrapper around the `apt` Debian & Ubuntu package management tool.
303
313
304
- <3> Each module then provides a bunch of parameters which control
305
- how it works. Here we specify the `name` of the package we want to install ("docker")
306
- and tell it update its cache first, which is required on a fresh server.
314
+ <3> Each module then provides a bunch of parameters which control how it works.
315
+ Here we specify the `name` of the package we want to install ("docker")
316
+ and tell it update its cache first, which is required on a fresh server.
307
317
308
318
Most ansible modules have pretty good documentation,
309
319
check out the `builtin.apt` one for example.
310
- I often skip to the https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html#examples[Examples section].
320
+ I often skip to the
321
+ https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html#examples[Examples section].
322
+
311
323
312
324
[subs="specialcharacters,quotes"]
313
325
314
326
----
315
327
$ *ansible-playbook --user=elspeth -i 192.168.56.10, infra/ansible-provision.yaml -vv*
328
+ PLAYBOOK: ansible-provision.yaml **********************************************
329
+ 1 plays in infra/ansible-provision.yaml
330
+
331
+ PLAY [all] ********************************************************************
332
+
333
+ TASK [Gathering Facts] ********************************************************
334
+ task path: ...goat-book/infra/ansible-provision.yaml:2
335
+ ok: [192.168.56.10]
336
+
337
+ TASK [Add Docker GPG apt Key] *************************************************
338
+ task path: ...goat-book/infra/ansible-provision.yaml:9
339
+ changed: [192.168.56.10] => {"after": ["8D81803C0EBFCD88", "7EA0A9C3F273FCD8", "D94AA3F0EFE21092", "871920D1991BC93C"], "before": ["D94AA3F0EFE21092", "871920D1991BC93C"], "changed": true, "fp": "8D81803C0EBFCD88", "id": "8D81803C0EBFCD88", "key_id": "8D81803C0EBFCD88", "short_id": "0EBFCD88"}
340
+
341
+ TASK [Add Docker Repository] **************************************************
342
+ task path: ...goat-book/infra/ansible-provision.yaml:14
343
+ changed: [192.168.56.10] => {"changed": true, "repo": "deb https://download.docker.com/linux/ubuntu jammy stable", "sources_added": ["/etc/apt/sources.list.d/download_docker_com_linux_ubuntu.list"], "sources_removed": [], "state": "present"}
344
+
345
+ TASK [Update apt and install docker-ce] ***************************************
346
+ task path: ...goat-book/infra/ansible-provision.yaml:19
347
+ changed: [192.168.56.10] => {"cache_update_time": [...]
348
+ changed: [192.168.56.10] => {"cache_update_time": 1706583891, "cache_updated":
349
+ true, "changed": true, "stderr": "", "stderr_lines": [], "stdout": "Reading
350
+ package lists...\nBuilding dependency tree...\nReading state
351
+ information...\nThe following additional packages will be installed:\n
352
+ containerd.io docker-buildx-plugin docker-ce-cli docker-ce-rootless-extras\n
353
+ [...]
354
+ TASK [Add our user to Docker allowed users] ***********************************
355
+ changed: [192.168.56.10] => {"append": true, "changed": true, "comment": "",
356
+ "group": 1001, "groups": "docker", "home": "/home/elspeth", "move_home": false,
357
+ "name": "elspeth", "shell": "/bin/bash", "state": "present", "uid": 1001}
358
+ TASK [Run test container] *****************************************************
359
+ task path: ...goat-book/infra/ansible-provision.yaml:31
360
+ changed: [192.168.56.10] => {"changed": true, "container": {"AppArmorProfile":
361
+ "docker-default", "Args": ["hello", "world"], "Config": {"AttachStderr": true,
362
+ "AttachStdin": false, "AttachStdout": true, "Cmd": ["echo", "hello", "world"],
363
+ [...]
364
+
365
+ PLAY RECAP ***********************************************************
366
+ 192.168.56.10 : ok=6 changed=6 unreachable=0 failed=0
367
+ skipped=0 rescued=0 ignored=0
316
368
----
317
369
318
- TODO: show ansible output.
319
370
TODO: stop using local ip
320
371
321
372
373
+ ////
374
+
375
+ this goes wrong because groups don't work immediately:
376
+
377
+ TASK [Run test container] *****************************************************
378
+ fatal: [192.168.56.10]: FAILED! => {"changed": false, "msg": "Error connecting:
379
+ Error while fetching server API version: ('Connection aborted.',
380
+ PermissionError(13, 'Permission denied'))"}
381
+
382
+ waiting a few minutes fixes it
383
+
384
+ for now i'll just put become:true
385
+
386
+
387
+ ////
388
+
389
+
322
390
=== SSHing Into the Server and Viewing Container Logs
323
391
324
392
Now ssh into the server, check it worked
325
393
394
+ TODO: forget podman, just use docker.
326
395
327
396
[role="server-commands"]
328
397
[subs="specialcharacters,quotes"]
0 commit comments