Skip to content

Commit eea88b6

Browse files
committed
start getting 11 into shape
1 parent f044060 commit eea88b6

File tree

2 files changed

+55
-40
lines changed

2 files changed

+55
-40
lines changed

chapter_09_docker.asciidoc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,6 @@ How will containerizing our software help with the danger areas?
213213
// TODO: consider getting rid of the staging server??
214214

215215

216-
////
217-
footnote:[What I'm calling a "staging" server, some people would
218-
call a "development" server, and some others would also like to distinguish
219-
"preproduction" servers. Whatever we call it, the point is to have
220-
somewhere we can try our code out in an environment that's as similar as
221-
possible to the real production server.]
222-
////
223216

224217
////
225218

chapter_11_ansible.asciidoc

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[[chapter_11_ansible]]
2-
== Infrastructure As Code with Ansbile
2+
== Infrastructure As Code: Automated Deployments With Ansbile
33

44
[quote, 'Cay Horstman']
55
______________________________________________________________
@@ -17,13 +17,17 @@ but a key insight of the modern infrastructure management
1717
is that automation really pays off in reducing maintenance burdens.
1818

1919
It's also key to making sure our tests give us true confidence over our deployments.
20-
If we go to the trouble of builiding a staging server,
20+
If we go to the trouble of building a staging server,footnote:[
21+
What I'm calling a "staging" server, some people would
22+
call a "development" server, and some others would also like to distinguish
23+
"preproduction" servers. Whatever we call it, the point is to have
24+
somewhere we can try our code out in an environment that's as similar as
25+
possible to the real production server.]
2126
we want to make sure that it's as similar as possible to the production environment.
2227
By automating the way we deploy, and using the same automation for staging and prod,
2328
we give ourselves much more confidence.
2429

25-
The buzzword for automating your deployments these days is
26-
"Infrastructure as Code".
30+
The buzzword for automating your deployments these days is "Infrastructure as Code".
2731

2832
NOTE: Why not ping me a note once your site is live on the web,
2933
and send me the URL?
@@ -101,7 +105,6 @@ but they broadly fall into two camps:
101105
offering like Heroku or my old employers, PythonAnywhere.
102106

103107

104-
105108
((("PythonAnywhere")))
106109
Particularly for small sites, a PaaS offers a lot of advantages,
107110
and I would definitely recommend looking into them.
@@ -113,9 +116,10 @@ doesn't necessarily tell you about the others.
113116
Any one of them might radically change their process or business model by the time you get to read this book.
114117

115118
Instead, we'll learn just a tiny bit of good old-fashioned server admin,
116-
including SSH and manual server config. They're unlikely to ever go away, and
117-
knowing a bit about them will get you some respect from all the grizzled
118-
dinosaurs out there.
119+
including SSH and manual server config.
120+
They're unlikely to ever go away,
121+
and knowing a bit about them will get you some respect
122+
from all the grizzled dinosaurs out there.
119123

120124

121125

@@ -146,9 +150,9 @@ https://github.com/hjwp/Book-TDD-Web-Dev-Python/blob/master/server-quickstart.md
146150

147151
NOTE: Some people get to this chapter, and are tempted to skip the domain bit,
148152
and the "getting a real server" bit, and just use a VM on their own PC.
149-
Don't do this. It's 'not' the same, and you'll have more difficulty
150-
following the instructions, which are complicated enough as it is. If
151-
you're worried about cost, have a look at the link above for free options.
153+
Don't do this. It's _not_ the same, and you'll have more difficulty
154+
following the instructions, which are complicated enough as it is.
155+
If you're worried about cost, have a look at the link above for free options.
152156
((("getting help")))
153157

154158

@@ -165,12 +169,12 @@ Just remember to substitute it in all the places I've hardcoded it below.
165169
See the guide linked above if you need tips on creating a sudo user.
166170

167171

168-
169172
.General Server Debugging Tips
170173
*******************************************************************************
171174
172-
The most important lesson to remember from this chapter is to work
173-
incrementally, make one change at a time, and run your tests frequently.
175+
The most important lesson to remember from this chapter is,
176+
as always but more than ever, to work incrementally,
177+
make one change at a time, and run your tests frequently.
174178
175179
When things (inevitably) go wrong, resist the temptation to flail about
176180
and make other unrelated changes in the hope that things will start working again;
@@ -183,11 +187,7 @@ It's just as easy to fall into the Refactoring-Cat trap on the server!
183187

184188

185189

186-
187-
188-
189-
Configuring Domains for Staging and Live
190-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
190+
=== Configuring Domains for Staging and Live
191191

192192
We don't want to be messing about with IP addresses all the time,
193193
so we should point our staging and live domains to the server.
@@ -213,16 +213,10 @@ so once you've set up your A-record,
213213
you can check its progress on a "propagation checking" service like this one:
214214
https://www.whatsmydns.net/#A/superlists-staging.ottg.eu.
215215

216-
////
217216
I'm planning to host my staging server at 'superlists-staging.ottg.eu':
218217

219218

220-
NOTE: A clarification: in this chapter, we run tests 'against' our staging
221-
server, not 'on' our staging server. So we still run the tests from our
222-
own laptop, but they target the site that's running on the server.
223-
////
224-
225-
=== A first cut of an ansible script
219+
=== A first Cut of an Ansible Script
226220

227221
Infrastructure-as-code tools, also called "configuration management" tools,
228222
come in lots of shapes and sizes.
@@ -231,8 +225,8 @@ and you'll probably come across Terraform,
231225
which is particularly strong on managing cloud services like AWS.
232226

233227
We're going to use Ansible, because it's relatively popular,
234-
because I'm biased that it happens to be written in Python,
235228
because it can do everything we need it to,
229+
because I'm biased that it happens to be written in Python,
236230
and because it's probably the one I'm personally most familiar with.
237231

238232
Another tool could probably have worked just as well!
@@ -243,7 +237,16 @@ rather than specifying a procedural series of steps to be followed one by one.
243237

244238

245239
Let's dip our toes into ansible,
246-
and see if we can get it to run a simple "hello world" container on our server:
240+
and see if we can get it to run a simple "hello world" container on our server.
241+
242+
Here's what's called a "playbook" in ansible terminology.
243+
It's in a format called YAML (Yet Another Markup Language),
244+
which, if you've never come across before,
245+
you will soon develop a love-hatefootnote:[
246+
The "love" part is that yaml is very easy to _read_ and scan through at a glance.
247+
The "hate" part is that the actual syntax is surprisingly fiddly to get right:
248+
the difference between lists and key/value maps is subtle and I can never quite remember it honestly.]
249+
relationship with.
247250

248251

249252
[role="sourcecode"]
@@ -255,9 +258,9 @@ and see if we can get it to run a simple "hello world" container on our server:
255258
- hosts: all
256259
257260
tasks:
258-
- name: Install podman
259-
ansible.builtin.apt:
260-
name: podman
261+
- name: Install podman <1>
262+
ansible.builtin.apt: <2>
263+
name: podman <3>
261264
update_cache: yes
262265
become: true
263266
@@ -270,12 +273,31 @@ and see if we can get it to run a simple "hello world" container on our server:
270273
----
271274
====
272275

276+
<1> An ansible playbook is a series of "tasks"
277+
(so in that sense it's still quite sequential and procedural),
278+
but the individual tasks themselves are quite declarative.
279+
Each one usually has a human-readable `name` attribute.
280+
281+
<2> Each tasks uses an ansible "module" to do its work.
282+
This one uses the `builtin.apt` module which provides
283+
a wrapper around the `apt` Debian & Ubuntu package management tool.
284+
285+
<3> Each module then provides a bunch of parameters which control
286+
how it works. Here we specify the `name` of the package we want to install ("docker")
287+
and tell it update its cache first, which is required on a fresh server.
288+
289+
Most ansible modules have pretty good documentation,
290+
check out the `builtin.apt` one for example.
291+
I often skip to the https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html#examples[Examples section].
292+
273293
[subs="specialcharacters,quotes"]
294+
274295
----
275296
$ *ansible-playbook --user=elspeth -i 192.168.56.10, infra/ansible-provision.yaml -vv*
276297
----
277298

278-
TODO show ansible output.
299+
TODO: show ansible output.
300+
TODO: stop using local ip
279301

280302

281303
=== SSHing Into the Server and Viewing Container Logs
@@ -479,7 +501,7 @@ Ansible and the podman plugins have some modules for this:
479501
containers.podman.podman_generate_systemd:
480502
name: superlists
481503
dest: ~/.config/systemd/user/
482-
504+
483505
- name: Container must be started and enabled on systemd
484506
ansible.builtin.systemd:
485507
name: container-superlists

0 commit comments

Comments
 (0)