Skip to content

Commit a0ea1ce

Browse files
committed
idempotency in 11 and fix submodule
1 parent 0aecd8e commit a0ea1ce

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

chapter_11_ansible.asciidoc

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,9 @@ This means we don't have a dependency on having run `docker build` locally.
541541
source: build
542542
state: present
543543
build:
544-
path: ../Dockerfile
544+
path: ..
545545
platform: linux/amd64 # <1>
546+
force_source: true
546547
delegate_to: 127.0.0.1
547548
548549
- name: Export container image locally
@@ -668,17 +669,37 @@ And here's how we use it in the provisioning script:
668669
but I'm renaming it for clarity.
669670

670671

671-
.Idempotency
672-
*******************************************************************************
673-
* TODO: explain idempotency
674-
675-
*******************************************************************************
676-
677672
NOTE: Using an env file to store secrets is definitely better than committing
678673
it to version control, but it's maybe not the state of the art either.
679674
TODO: mention other secret management tools. vault
680675

681676

677+
.Idempotency and Declarative Configuration
678+
*******************************************************************************
679+
680+
Infrastucture-as-code tools like Ansible aim to be "declarative",
681+
meaning that, as much as possible, you specify the desired state that you want,
682+
rather than specifying a series of steps to get there.
683+
684+
This concept goes along with the idea of "idempotency",
685+
which means that you get the same result when you run something once,
686+
as when you run it multiple times.
687+
688+
An example is the `apt` module that we used to install docker.
689+
It doesn't crash if docker is already installed, and in fact,
690+
Ansible is smart enough to check first before trying to install anything.
691+
692+
There is some subtlety here, for example, our templated env file
693+
will only be writen once, so the step is idempotent in the sense
694+
that it doesn't overwrite the file with a new random secret key every time you run it.
695+
But that does come with the downside that you can't easily add new variables to the file.
696+
697+
Probably a more sophisticated solution involving separate files for the secret
698+
and other parts of the config would be better,
699+
but I wanted to keep this (already long) chapter as simple as possible.
700+
701+
*******************************************************************************
702+
682703

683704
==== More debugging
684705

0 commit comments

Comments
 (0)