{"id":364,"date":"2026-11-29T12:00:00","date_gmt":"2026-11-29T12:00:00","guid":{"rendered":"https:\/\/rezachegini.com\/?p=364"},"modified":"2026-11-29T19:25:32","modified_gmt":"2026-11-29T19:25:32","slug":"building-a-job-board-api-part-31-installed-is-not-the-same-as-working","status":"publish","type":"post","link":"https:\/\/rezachegini.com\/?p=364","title":{"rendered":"Building a Job Board API, Part 31: Installed Is Not the Same as Working"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Where we are<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hi, I&#8217;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Parts 29 and 30, I built dev-toolchain, a shared Ansible role that installs a project&#8217;s local tools, and published it as v0.1.0. The Job Board API pins it and runs it with bootstrap.yml.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But &#8220;installed&#8221; is not the same as &#8220;working&#8221;. The role checks if a tool is present. It doesn&#8217;t check if the tool runs. A broken symlink, a missing plugin, or a tool that can&#8217;t reach Docker would all pass.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Setup checklist&#8217;s item 2 asks for this: a verify task that prints each tool&#8217;s version and fails if a tool is missing. In this part I build it, with three goals:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Print one clear line per tool, like redis-cli: redis-cli 8.0.5.<\/li>\n\n\n\n<li>Report every broken tool in one run, not just the first one.<\/li>\n\n\n\n<li>Work as a health check on its own, without installing anything.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1463\" height=\"415\" src=\"http:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-31-diagram.png\" alt=\"Check every tool, then fail once with every broken name\" class=\"wp-image-363\" srcset=\"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-31-diagram.png 1463w, https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-31-diagram-300x85.png 300w, https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-31-diagram-1024x290.png 1024w, https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-31-diagram-768x218.png 768w\" sizes=\"auto, (max-width: 1463px) 100vw, 1463px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">One check command per tool<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Full paths for user-level tools: ~\/.local\/bin may not be on Ansible's PATH yet on a fresh machine.\ntoolchain_bin: \"{{ ansible_facts['user_dir'] }}\/.local\/bin\"\n\ntoolchain_verify:\n  postgresql-client: \"psql --version\"\n  redis-cli: \"redis-cli --version\"\n  awscli: \"aws --version\"\n  localstack: \"{{ toolchain_bin }}\/lstk --version\"\n  pre-commit: \"{{ toolchain_bin }}\/pre-commit --version\"\n  uv: \"{{ toolchain_uv }} --version\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ansible&#8217;s commands don&#8217;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most checks are that simple. Four were more interesting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Docker: two parts, one line, and an echo trap<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>docker: \"d=$(docker --version) &amp;&amp; c=$(docker compose version) &amp;&amp; echo \\\"$d; $c\\\"\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An assignment from $( \u2026 ) takes the command&#8217;s exit code. So if either command fails, the &amp;&amp; chain stops and the check fails.<\/li>\n\n\n\n<li>The trap: echo &#8220;$(docker &#8211;version); $(docker compose version)&#8221; looks the same, but it would exit 0 even if Docker were missing, because echo always succeeds.<\/li>\n\n\n\n<li>Both are client-only commands. They don&#8217;t need the Docker daemon, so no sudo.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Python 3.12: run the real interpreter<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>python3.12: \"\\\"$({{ toolchain_uv }} python find 3.12)\\\" --version\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">uv python find 3.12 prints the path of the interpreter, and &#8220;$( \u2026 )&#8221; &#8211;version runs that interpreter&#8217;s &#8211;version. So the check tests the real interpreter, not just uv.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">awslocal: keep only the line that matters<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>awslocal: \"{{ toolchain_bin }}\/lstk aws --version | grep aws-cli\/\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">lstk aws passes &#8211;version on to the AWS CLI. But lstk first prints a note on stdout: &gt; Note: No AWS profile found, run &#8216;lstk setup aws&#8217;. So the check pipes the output through grep aws-cli\/, and only the AWS CLI version line survives.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Azurite: an image has no version command<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>azurite: \"docker image ls --quiet {{ toolchain_azurite_image }} | grep -q . &amp;&amp; echo {{ toolchain_azurite_image }}\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>docker image ls &#8211;quiet IMAGE prints the image ID if it exists, and nothing if it doesn&#8217;t. It exits 0 either way.<\/li>\n\n\n\n<li>grep -q . succeeds only if there was output. That turns &#8220;no image&#8221; into a failure.<\/li>\n\n\n\n<li>&amp;&amp; echo IMAGE prints the image name, which is the meaningful &#8220;version&#8221; here.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">My first version used grep . without -q, so it printed the image ID (830430c1da1a) as the summary line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">verify.yml: three tasks<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">1. Run every check, and never fail here<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: \"verify | run each tool's version command\"\n  ansible.builtin.shell: \"{{ toolchain_verify[tool] }}\"\n  args:\n    executable: \/bin\/bash\n  loop: \"{{ toolchain_tools }}\"\n  loop_control:\n    loop_var: tool\n    label: \"{{ tool }}\"\n  register: toolchain_versions\n  changed_when: false\n  failed_when: false\n  become: \"{{ tool == 'azurite' }}\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>shell, not command. Several checks use $( \u2026 ), &amp;&amp; and |, which command doesn&#8217;t run. Ansible&#8217;s guidelines prefer command when no shell is needed. Here, it is needed.<\/li>\n\n\n\n<li>executable: \/bin\/bash. Ansible&#8217;s default shell is \/bin\/sh, which is dash on Ubuntu. My commands only use POSIX features, but naming bash makes the behaviour certain.<\/li>\n\n\n\n<li>loop: toolchain_tools. A project checks only what it asked for.<\/li>\n\n\n\n<li>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.<\/li>\n\n\n\n<li>changed_when: false keeps changed=0, because a check changes nothing.<\/li>\n\n\n\n<li>failed_when: false is the key line. A broken tool doesn&#8217;t stop the loop, so every tool gets checked.<\/li>\n\n\n\n<li>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.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. Print one line per tool<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: \"verify | version of each tool\"\n  ansible.builtin.debug:\n    msg: &gt;-\n      {{ result.tool }}:\n      {{ ((result.stdout_lines or result.stderr_lines) | first | default('(no output)'))\n        if result.rc == 0 else\n        'MISSING OR BROKEN (exit ' ~ result.rc ~ '): ' ~ ((result.stderr_lines or result.stdout_lines) | last | default('(no output)')) }}\n    loop: \"{{ toolchain_versions.results }}\"\n    loop_control:\n      loop_var: result\n      label: \"{{ result.tool }}\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This looks scary, so step by step:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&gt;- is a YAML folded block. The lines join into one string, which keeps a long template readable.<\/li>\n\n\n\n<li>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.<\/li>\n\n\n\n<li>A broken tool: MISSING OR BROKEN (exit N): plus the last error line, which is usually the reason. stderr_lines first, then stdout_lines.<\/li>\n\n\n\n<li>~ is Jinja2&#8217;s string join. It also turns the number rc into text.<\/li>\n\n\n\n<li>default(&#8216;(no output)&#8217;) covers a command that printed nothing.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A broken tool looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli: MISSING OR BROKEN (exit 127): \/bin\/bash: line 1: redis-cli: command not found<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Exit 127 is the shell&#8217;s code for &#8220;command not found&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Fail once, naming everything broken<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: \"verify | every requested tool works\"\n  ansible.builtin.assert:\n    that:\n      - toolchain_broken | length == 0\n    fail_msg: \"Missing or broken: {{ toolchain_broken | join(', ') }} (see the version lines above)\"\n    quiet: true\n  vars:\n    toolchain_broken: \"{{ toolchain_versions.results | rejectattr('rc', 'equalto', 0) | map(attribute='tool') | list }}\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>rejectattr(&#8216;rc&#8217;, &#8216;equalto&#8217;, 0) drops the results with rc 0, so only the broken ones remain. map(attribute=&#8217;tool&#8217;) keeps the tool names, so toolchain_broken is a list of names.<\/li>\n\n\n\n<li>The assert fails the play if anything is broken, and the message names them all.<\/li>\n\n\n\n<li>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&#8217;s &#8216;fails if a tool is missing&#8217;.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A health check with &#8211;tags verify<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In tasks\/main.yml, the verify step runs last, after the install loop, so it checks the result of installing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: Verify every requested tool\n  ansible.builtin.import_tasks: verify.yml\n  tags: [verify]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here import_tasks matters, not include_tasks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A tag on an import (static) is copied onto every task inside the file.<\/li>\n\n\n\n<li>A tag on an include (dynamic) applies only to the include itself. So &#8211;tags verify would skip everything except the include line.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now ansible-playbook \u2026 &#8211;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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Releasing v0.2.0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>git tag -a v0.2.0 -m \"dev-toolchain v0.2.0: verify step (versions + clear failure), --tags verify health check\"\ngit push origin v0.2.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is a minor bump, from 0.1 to 0.2. In semantic versioning, that means &#8220;a new feature, nothing broken for existing users&#8221;. A patch bump (0.1.1) would mean bug fixes only.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then the project opts in, by changing its pin:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sed -i 's\/    version: v0.1.0\/    version: v0.2.0\/' requirements.yml\nansible-galaxy role install -r requirements.yml --force<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;force is needed, because Galaxy sees dev-toolchain installed and skips it. It doesn&#8217;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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Results<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The role&#8217;s test, two full runs: 10 version lines, ok=46 changed=0 failed=0 skipped=21 both times. Verify adds output, not changes.<\/li>\n\n\n\n<li>&#8211;tags verify: the 10 lines, and ok=4. No install tasks at all.<\/li>\n\n\n\n<li>The negative test. I hid redis-cli with sudo mv and ran &#8211;tags verify:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli: MISSING OR BROKEN (exit 127): \/bin\/bash: line 1: redis-cli: command not found\nMissing or broken: redis-cli (see the version lines above)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>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.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The versions on thor:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python 3.12.15<\/li>\n\n\n\n<li>Docker 29.7.2 + Compose v5.5.0<\/li>\n\n\n\n<li>psql 18.6<\/li>\n\n\n\n<li>redis-cli 8.0.5<\/li>\n\n\n\n<li>aws-cli 2.40.2<\/li>\n\n\n\n<li>lstk 1.4.5<\/li>\n\n\n\n<li>awslocal (through lstk): aws-cli 2.40.2<\/li>\n\n\n\n<li>Azurite image 3.37.0<\/li>\n\n\n\n<li>pre-commit 4.7.0<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Problems I hit<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Three summary lines said the wrong thing, while the checks passed.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>awslocal: &gt; Note: No AWS profile found, run &#8216;lstk setup aws&#8217;. lstk&#8217;s note comes first on stdout.<\/li>\n\n\n\n<li>azurite: 830430c1da1a. The image ID came before the name.<\/li>\n\n\n\n<li>Docker&#8217;s first command, docker &#8211;version &amp;&amp; docker compose version, worked, but it printed two lines, and only the first was shown.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The fix: each command now prints exactly one meaningful line. | grep aws-cli\/ for awslocal, grep -q . for Azurite, and the d=$(&#8230;) &amp;&amp; c=$(&#8230;) form for Docker, which puts both versions on one line without losing the failure on either.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The lesson: a check passing is not enough. Its output must also say the right thing, or people stop reading it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. One pasted output was cut. The &#8211;tags verify summary line was missing from one paste. The same check had already passed in the role&#8217;s own test (ok=4 failed=0), so I didn&#8217;t rerun it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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&#8217;t run there, because there was no Docker daemon. It was first proven on thor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What I learned<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Collect, then fail once. failed_when: false in the loop, and one assert at the end. Every broken tool shows up in one run.<\/li>\n\n\n\n<li>Exit codes are the contract. Chain with &amp;&amp;. Use grep -q to turn &#8220;no output&#8221; into a failure. And remember exit 127 means &#8220;command not found&#8221;.<\/li>\n\n\n\n<li>echo always succeeds. Wrapping commands inside echo &#8220;$( \u2026 )&#8221; hides their failures.<\/li>\n\n\n\n<li>A tag on import_tasks reaches every task inside. A tag on include_tasks doesn&#8217;t.<\/li>\n\n\n\n<li>become can come from an expression, per loop item.<\/li>\n\n\n\n<li>Always run the negative test. Hide a tool, and make sure the run fails with its name.<\/li>\n\n\n\n<li>Semantic versioning tells users what changed. A minor bump for a new feature, and each project opts in by changing its pin.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What is next<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This completes Setup checklist item 2. Next is the Setup&#8217;s &#8220;Done when&#8221; 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.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Where we are Hi, I&#8217;m Reza. In my newsletter, Root Access, I am sharing one of my projects from the very beginning:&hellip;<\/p>\n","protected":false},"author":2,"featured_media":362,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_rezaops_part":"31","_rezaops_linkedin_url":"https:\/\/www.linkedin.com\/pulse\/building-job-board-api-part-31-installed-same-working-reza-chegini-9rl0c\/","footnotes":""},"categories":[63,85,10,116,74],"tags":[65,60,222,8,111,35,118,194,223,25,112,17,221],"series":[117],"class_list":["post-364","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible","category-aws","category-devops","category-django","category-linux","tag-ansible","tag-aws","tag-azurite","tag-devops","tag-django","tag-docker","tag-job-board","tag-localstack","tag-pre-commit","tag-python","tag-rest-api","tag-ubuntu","tag-uv","series-job-board-api"],"jetpack_featured_media_url":"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-31-cover.png","_links":{"self":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=364"}],"version-history":[{"count":1,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/364\/revisions"}],"predecessor-version":[{"id":365,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/364\/revisions\/365"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/media\/362"}],"wp:attachment":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=364"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}