$ cat job-board-api/part-31.md
Building a Job Board API, Part 31: Installed Is Not the Same as Working

Where we are
Hi, I’m Reza. In my newsletter, Root Access, I am sharing one of my projects from the very beginning: a Job Board API built with Django, Postgres, Docker, AWS and Azure. I am a junior engineer looking for my first SRE, DevOps or Cloud job, and that is why I build my projects in public. You can see how I think, what breaks, and how I fix it.
In Parts 29 and 30, I built dev-toolchain, a shared Ansible role that installs a project’s local tools, and published it as v0.1.0. The Job Board API pins it and runs it with bootstrap.yml.
But “installed” is not the same as “working”. The role checks if a tool is present. It doesn’t check if the tool runs. A broken symlink, a missing plugin, or a tool that can’t reach Docker would all pass.
The Setup checklist’s item 2 asks for this: a verify task that prints each tool’s version and fails if a tool is missing. In this part I build it, with three goals:
- Print one clear line per tool, like redis-cli: redis-cli 8.0.5.
- Report every broken tool in one run, not just the first one.
- Work as a health check on its own, without installing anything.

The trick is in the order. The checks never fail by themselves. They only collect results. The last task decides, so one run can name every broken tool.
One check command per tool
The rule for every check: exit 0 and print the version if the tool works. A non-zero exit means broken. The commands live in defaults/main.yml as a lookup table, from tool name to command. It is data, not code, so a project could override one check.
# Full paths for user-level tools: ~/.local/bin may not be on Ansible's PATH yet on a fresh machine.
toolchain_bin: "{{ ansible_facts['user_dir'] }}/.local/bin"
toolchain_verify:
postgresql-client: "psql --version"
redis-cli: "redis-cli --version"
awscli: "aws --version"
localstack: "{{ toolchain_bin }}/lstk --version"
pre-commit: "{{ toolchain_bin }}/pre-commit --version"
uv: "{{ toolchain_uv }} --version"
Ansible’s commands don’t run a login shell, so ~/.local/bin may not be on their PATH, especially on a fresh machine where the folder was just created. So the user-level tools use full paths. The apt tools are in /usr/bin, which is always on the PATH.
Most checks are that simple. Four were more interesting.
Docker: two parts, one line, and an echo trap
docker: "d=$(docker --version) && c=$(docker compose version) && echo \"$d; $c\""
Docker has two parts: the engine CLI and the Compose v2 plugin. The check needs both, on one line: Docker version 29.7.2, build a7dcaa6; Docker Compose version v5.5.0.
- An assignment from $( … ) takes the command’s exit code. So if either command fails, the && chain stops and the check fails.
- The trap: echo “$(docker –version); $(docker compose version)” looks the same, but it would exit 0 even if Docker were missing, because echo always succeeds.
- Both are client-only commands. They don’t need the Docker daemon, so no sudo.
Python 3.12: run the real interpreter
python3.12: "\"$({{ toolchain_uv }} python find 3.12)\" --version"
uv python find 3.12 prints the path of the interpreter, and “$( … )” –version runs that interpreter’s –version. So the check tests the real interpreter, not just uv.
awslocal: keep only the line that matters
awslocal: "{{ toolchain_bin }}/lstk aws --version | grep aws-cli/"
lstk aws passes –version on to the AWS CLI. But lstk first prints a note on stdout: > Note: No AWS profile found, run ‘lstk setup aws’. So the check pipes the output through grep aws-cli/, and only the AWS CLI version line survives.
Azurite: an image has no version command
azurite: "docker image ls --quiet {{ toolchain_azurite_image }} | grep -q . && echo {{ toolchain_azurite_image }}"
- docker image ls –quiet IMAGE prints the image ID if it exists, and nothing if it doesn’t. It exits 0 either way.
- grep -q . succeeds only if there was output. That turns “no image” into a failure.
- && echo IMAGE prints the image name, which is the meaningful “version” here.
My first version used grep . without -q, so it printed the image ID (830430c1da1a) as the summary line.
verify.yml: three tasks
1. Run every check, and never fail here
- name: "verify | run each tool's version command"
ansible.builtin.shell: "{{ toolchain_verify[tool] }}"
args:
executable: /bin/bash
loop: "{{ toolchain_tools }}"
loop_control:
loop_var: tool
label: "{{ tool }}"
register: toolchain_versions
changed_when: false
failed_when: false
become: "{{ tool == 'azurite' }}"
- shell, not command. Several checks use $( … ), && and |, which command doesn’t run. Ansible’s guidelines prefer command when no shell is needed. Here, it is needed.
- executable: /bin/bash. Ansible’s default shell is /bin/sh, which is dash on Ubuntu. My commands only use POSIX features, but naming bash makes the behaviour certain.
- loop: toolchain_tools. A project checks only what it asked for.
- register in a loop gives a list, toolchain_versions.results, with one entry per tool. Each entry has rc, stdout_lines, stderr_lines, and the loop variable tool.
- changed_when: false keeps changed=0, because a check changes nothing.
- failed_when: false is the key line. A broken tool doesn’t stop the loop, so every tool gets checked.
- become from an expression. It is true only for Azurite, because its check talks to the Docker daemon. The other tools run as the normal user.
2. Print one line per tool
- name: "verify | version of each tool"
ansible.builtin.debug:
msg: >-
{{ result.tool }}:
{{ ((result.stdout_lines or result.stderr_lines) | first | default('(no output)'))
if result.rc == 0 else
'MISSING OR BROKEN (exit ' ~ result.rc ~ '): ' ~ ((result.stderr_lines or result.stdout_lines) | last | default('(no output)')) }}
loop: "{{ toolchain_versions.results }}"
loop_control:
loop_var: result
label: "{{ result.tool }}"
This looks scary, so step by step:
- >- is a YAML folded block. The lines join into one string, which keeps a long template readable.
- A working tool (rc == 0): the first line of stdout, or of stderr if stdout is empty, because some tools print their version to stderr. That is why the template tries stdout_lines, then stderr_lines.
- A broken tool: MISSING OR BROKEN (exit N): plus the last error line, which is usually the reason. stderr_lines first, then stdout_lines.
- ~ is Jinja2’s string join. It also turns the number rc into text.
- default(‘(no output)’) covers a command that printed nothing.
A broken tool looks like this:
redis-cli: MISSING OR BROKEN (exit 127): /bin/bash: line 1: redis-cli: command not found
Exit 127 is the shell’s code for “command not found”.
3. Fail once, naming everything broken
- name: "verify | every requested tool works"
ansible.builtin.assert:
that:
- toolchain_broken | length == 0
fail_msg: "Missing or broken: {{ toolchain_broken | join(', ') }} (see the version lines above)"
quiet: true
vars:
toolchain_broken: "{{ toolchain_versions.results | rejectattr('rc', 'equalto', 0) | map(attribute='tool') | list }}"
- rejectattr(‘rc’, ‘equalto’, 0) drops the results with rc 0, so only the broken ones remain. map(attribute=’tool’) keeps the tool names, so toolchain_broken is a list of names.
- The assert fails the play if anything is broken, and the message names them all.
- The run exits non-zero (failed=1). So a script or a CI job that runs the bootstrap sees the failure. That is the spec’s ‘fails if a tool is missing’.
The other option was to fail on the first broken tool. But then you fix one tool per run. This way, one run shows everything.
A health check with –tags verify
In tasks/main.yml, the verify step runs last, after the install loop, so it checks the result of installing:
- name: Verify every requested tool
ansible.builtin.import_tasks: verify.yml
tags: [verify]
Here import_tasks matters, not include_tasks:
- A tag on an import (static) is copied onto every task inside the file.
- A tag on an include (dynamic) applies only to the include itself. So –tags verify would skip everything except the include line.
Now ansible-playbook … –tags verify runs only the three verify tasks. Fact gathering still runs, because toolchain_uv and toolchain_bin need it. It is a health check for a machine, without installing anything.
Releasing v0.2.0
git tag -a v0.2.0 -m "dev-toolchain v0.2.0: verify step (versions + clear failure), --tags verify health check"
git push origin v0.2.0
This is a minor bump, from 0.1 to 0.2. In semantic versioning, that means “a new feature, nothing broken for existing users”. A patch bump (0.1.1) would mean bug fixes only.
Then the project opts in, by changing its pin:
sed -i 's/ version: v0.1.0/ version: v0.2.0/' requirements.yml
ansible-galaxy role install -r requirements.yml --force
–force is needed, because Galaxy sees dev-toolchain installed and skips it. It doesn’t compare versions for git sources. The output confirmed the switch: changing role dev-toolchain from v0.1.0 to v0.2.0. Other projects stay on whatever they pinned.
Results
- The role’s test, two full runs: 10 version lines, ok=46 changed=0 failed=0 skipped=21 both times. Verify adds output, not changes.
- –tags verify: the 10 lines, and ok=4. No install tasks at all.
- The negative test. I hid redis-cli with sudo mv and ran –tags verify:
redis-cli: MISSING OR BROKEN (exit 127): /bin/bash: line 1: redis-cli: command not found
Missing or broken: redis-cli (see the version lines above)
The run ended with failed=1. Then I put redis-cli back, and it reported redis-cli 8.0.5 again. A check that can never fail proves nothing, so this test matters as much as the green run.
- The project on v0.2.0: bootstrap.yml printed 9 version lines, with no warnings, and ok=43 changed=0 failed=0. The project gets the verify step through its pinned dependency.
The versions on thor:
- Python 3.12.15
- Docker 29.7.2 + Compose v5.5.0
- psql 18.6
- redis-cli 8.0.5
- aws-cli 2.40.2
- lstk 1.4.5
- awslocal (through lstk): aws-cli 2.40.2
- Azurite image 3.37.0
- pre-commit 4.7.0
Problems I hit
1. Three summary lines said the wrong thing, while the checks passed.
- awslocal: > Note: No AWS profile found, run ‘lstk setup aws’. lstk’s note comes first on stdout.
- azurite: 830430c1da1a. The image ID came before the name.
- Docker’s first command, docker –version && docker compose version, worked, but it printed two lines, and only the first was shown.
The fix: each command now prints exactly one meaningful line. | grep aws-cli/ for awslocal, grep -q . for Azurite, and the d=$(…) && c=$(…) form for Docker, which puts both versions on one line without losing the failure on either.
The lesson: a check passing is not enough. Its output must also say the right thing, or people stop reading it.
2. One pasted output was cut. The –tags verify summary line was missing from one paste. The same check had already passed in the role’s own test (ok=4 failed=0), so I didn’t rerun it.
Tested before thor, with one gap. The whole verify step, including the failure path with redis-cli hidden, worked in my test environment before I ran it on thor. The Azurite check couldn’t run there, because there was no Docker daemon. It was first proven on thor.
What I learned
- Collect, then fail once. failed_when: false in the loop, and one assert at the end. Every broken tool shows up in one run.
- Exit codes are the contract. Chain with &&. Use grep -q to turn “no output” into a failure. And remember exit 127 means “command not found”.
- echo always succeeds. Wrapping commands inside echo “$( … )” hides their failures.
- A tag on import_tasks reaches every task inside. A tag on include_tasks doesn’t.
- become can come from an expression, per loop item.
- Always run the negative test. Hide a tool, and make sure the run fails with its name.
- Semantic versioning tells users what changed. A minor bump for a new feature, and each project opts in by changing its pin.
What is next
This completes Setup checklist item 2. Next is the Setup’s “Done when” check: one command on a fresh machine, and changed=0 on the second run. Spoiler: the fresh machine found two real bugs that thor had been hiding.