Skip to content

Commit be245fc

Browse files
authored
Merge pull request #232 from seddonym/review-11-seddonym
Review Ansible chapter
2 parents 8b5d15d + 8710844 commit be245fc

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

chapter_10_production_readiness.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ It's not quite working yet! Let's take a look manually: <<django-400-error>>.
555555
.An ugly 400 error
556556
image::images/twp2_1002.png["An unfriendly page showing 400 Bad Request"]
557557

558+
// DAVID: noticed in passing that the screenshots in this chapter are from the hosted version
559+
// which isn't covered until next chapter.
560+
558561
We've set our two environment variables but doing so seems to have broken things.
559562
But once again, by running our FTs frequently,
560563
we're able to identify the problem early,

chapter_11_ansible.asciidoc

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ just pick any old registrar and buy a cheap one--it
6969
should only cost you $5 or so, and you can even find free ones.
7070
I promise seeing your site on a "real" website will be a thrill.
7171

72+
// DAVID: just wondering if it's worth giving them the option to cheat and
73+
// specify a domain name in a hosts file?
7274

7375

7476
=== Manually Provisioning a Server to Host Our Site
@@ -187,6 +189,7 @@ wild place!
187189
((("Platform-As-A-Service (PaaS)")))
188190
*******************************************************************************
189191

192+
// DAVID: looks like plusbryan.com has changed hands.
190193
////
191194
192195
TODO: good advice but not quite sure it's phrased quite right for the new version of the chapter.
@@ -261,7 +264,7 @@ rather than specifying a procedural series of steps to be followed one by one.
261264

262265
==== Installing Ansible
263266

264-
Take a look at the https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html [documentation] for instructions on how to install Ansible/
267+
Take a look at the https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html [documentation] for instructions on how to install Ansible.
265268
// RITA: Please anchor all URLs to descriptive text.
266269

267270
The simplest thing to do is to install Ansible into the virtualenv
@@ -293,9 +296,11 @@ The "hate" part is that the actual syntax is surprisingly fiddly to get right:
293296
the difference between lists and key/value maps is subtle and I can never quite remember it honestly.]
294297
for.
295298

299+
// DAVID: I didn't know if this was an example or a file to create.
300+
// I think it's the latter, it would be good to make that clear.
296301

297302
[role="sourcecode"]
298-
.infra/ansible-provision.yaml (ch11l001)
303+
.infra/ansible-provision.yaml (ch11l001)
299304
====
300305
[source,yaml]
301306
----
@@ -342,7 +347,7 @@ I often skip to the
342347
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html#examples[Examples section].
343348

344349
// RITA: Please add a sentence or two to introduce the following code block.
345-
350+
// DAVID: +1, this wrong footed me.
346351
[subs="specialcharacters,quotes"]
347352
----
348353
$ *ansible-playbook --user=elspeth -i staging.ottg.co.uk, infra/ansible-provision.yaml -vv*
@@ -388,6 +393,25 @@ PLAY RECAP ********************************************************************
388393
staging.ottg.co.uk : ok=3 changed=2 unreachable=0 failed=0
389394
skipped=0 rescued=0 ignored=0
390395
----
396+
// DAVID: rather than having to edit the username and domains each time,
397+
// what about getting the reader to set them as environment variables at the beginning of the chapter?
398+
399+
// DAVID: I got ansible-playbook: error: unrecognized arguments: --vv
400+
// ansible==9.4.0
401+
// ansible-core==2.16.6
402+
// Changed it to -v
403+
404+
// DAVID: Then I got:
405+
// FAILED! => {"msg": "Missing sudo password"}
406+
// I don't have much context about what's going on here, e.g. there are several machines
407+
// this could be interacting with - my local, a container in my local,
408+
// the remote, a container in remote. Or maybe I'm contacting the wrong remote computer.
409+
// So not that clear how to troubleshoot.
410+
// (I did set up a sudo user on the server as per your github guide.)
411+
// Maybe giving a bit more explanation on what this command is doing would help.
412+
// UPDATE: got this working with `--ask-become-pass` - we discussed this in person.
413+
// But, as discussed, it is annoying to have to keep typing your password in when we could
414+
// authenticate with the ssh key. Could we change this?
391415

392416
I don't know about you, but whenever I make a terminal spew out a stream
393417
of output, I like to make little _brrp brrp brrp_ noises, a bit like the
@@ -425,6 +449,11 @@ elspeth@server:$ *docker logs testcontainer*
425449
hello world
426450
----
427451

452+
// DAVID: Got
453+
// permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
454+
// Sudo fixed it.
455+
// Update: I think better to add my user to the docker group before this point.
456+
428457
TIP: Look out for that `elspeth@server`
429458
in the command-line listings in this chapter.
430459
It indicates commands that must be run on the server,
@@ -570,6 +599,13 @@ false, "AttachStdout": true, "Cmd": ["gunicorn", "--bind", ":8888",
570599
[...]
571600
----
572601

602+
// DAVID: I got error during the 'Export container image locally' step.
603+
// FAILED! => {"changed": false, "msg": "Error connecting: Error while fetching server API version:
604+
// ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))"}
605+
// Update: I fixed it by doing ``sudo usermod -aG docker ${USER}`` on the remote machine.
606+
// Maybe worth getting them to shell in and run `docker run hello-world` to
607+
// check their user has permission.
608+
// DAVID: by the way it's getting annoying having to type my sudo password in all the time.
573609

574610
For completeness, let's also add a step to explicitly build the image locally.
575611
This means we don't have a dependency on having run `docker build` locally.
@@ -621,6 +657,10 @@ PORTS NAMES
621657
3a2e600fbe77 busybox "echo hello world" 2 days ago Exited (0) 10
622658
minutes ago testcontainer
623659
660+
// DAVID: I can also see superlists listed (though exited).
661+
// In any event, feels like needs a bit more explanation of
662+
// your thought process?
663+
624664
elspeth@server:$ *docker logs testcontainer*
625665
[2024-02-26 22:19:15 +0000] [1] [INFO] Starting gunicorn 21.2.0
626666
[2024-02-26 22:19:15 +0000] [1] [INFO] Listening at: http://0.0.0.0:8888 (1)
@@ -665,6 +705,9 @@ It's a common tool in Ansible scripts, and the syntax is very similar to Django'
665705

666706
Here's what our template for the env file will look like:
667707

708+
// DAVID: These days wouldn't it be called env.jinja as
709+
// per https://jinja.palletsprojects.com/en/3.1.x/templates/#template-file-extension?
710+
668711
[role="sourcecode"]
669712
.infra/env.j2 (ch11l004)
670713
====
@@ -799,9 +842,14 @@ staging.ottg.co.uk : ok=8 changed=6 unreachable=0 failed=0
799842
skipped=0 rescued=0 ignored=0
800843
----
801844

802-
Looks good! What do our tests think?
845+
// DAVID: suggest you get us to we shell in and see the env file there.
803846

847+
Looks good! What do our tests think?
804848

849+
// DAVID: this command assumes we'll be in a different working directory
850+
// to the previous command.
851+
// Also... I originally just pasted this as-is, which contacted YOUR server. Another
852+
// reason to get them to set environment variables at the start of the chapter.
805853
==== More debugging
806854

807855
We run our tests as usual and run into a new problem:
@@ -814,6 +862,9 @@ selenium.common.exceptions.WebDriverException: Message: Reached error page:
814862
about:neterror?e=connectionFailure&u=http%3A//staging.ottg.co.uk/[...]
815863
----
816864

865+
// DAVID: I got selenium.common.exceptions.NoSuchElementException
866+
// On the server, I get 'Host not found'.
867+
817868
That `neterror` makes me think it's another networking problem.
818869
Let's try `curl` locally:
819870

@@ -826,6 +877,8 @@ curl: (7) Failed to connect to staging.ottg.co.uk port 80 after 25 ms: Couldn't
826877
connect to server
827878
----
828879

880+
// DAVID: I was able to connect, and got Host not found.
881+
829882
Now let's ssh in and try `curl` from the server itself:
830883

831884
[subs="specialcharacters,quotes"]
@@ -892,6 +945,8 @@ selenium.common.exceptions.NoSuchElementException: Message: Unable to locate
892945
element: [id="id_list_table"]; [...]
893946
----
894947

948+
// DAVID: tests pass for me now! And I can create lists on the server...
949+
// Strange, I'm pretty sure I didn't run migrations.
895950

896951
=== Mounting the database on the server and running migrations
897952

@@ -905,6 +960,7 @@ $ *ssh elspeth@server docker logs superlists*
905960
django.db.utils.OperationalError: no such table: lists_list
906961
----
907962

963+
// DAVID: confused by this next para.
908964

909965
[subs="specialcharacters,quotes"]
910966
----
@@ -1001,6 +1057,7 @@ and reloads it automatically if it crashes.
10011057
(used to need systemd, now you can just set restart_policy.
10021058
////
10031059

1060+
// DAVID: Maybe you should say this debugging stuff at the beginning, not the end!
10041061

10051062
.More Debugging Tips and Commands
10061063
*******************************************************************************
@@ -1114,7 +1171,10 @@ You now have a live website! Tell all your friends!
11141171
Tell your mum, if no one else is interested!
11151172
And, in the next chapter, it's back to coding again.((("", startref="Fstage11")))
11161173

1117-
1174+
// DAVID: maybe more of a conclusion here? It's quite a heavy chapter,
1175+
// a bit of an anticlimax to stop here. I want some inspiring note to end on.
1176+
// In particular, how does this tie into TDD?
1177+
// DAVID: Also - now it's on staging, should we release to prod too?
11181178

11191179
=== Further Reading
11201180

0 commit comments

Comments
 (0)