Skip to main content

Build a Coder lab for testing Ansible playbooks

15 min read
#coder #ansible #docker #terraform #linux

These are the steps for my Testing Ansible playbooks in a Coder workspace project.

My main tool for testing Ansible roles is Ansible Molecule. This build is a proof of concept that shows the same kind of testing can be done in a Coder workspace.

This is only for my homelab. It is not a production setup; it is how I built it at home to try the idea out.

In the examples, coder.example.com, auth.example.com, 192.168.1.50 and <github-user> stand for your own domain, IP address and GitHub account.

What we are building

The full build, from scratch: Coder VM, then the Coder server, the template, the ansible-sandbox workspace and the test targets (rocky8, rocky9, ubuntu2204).

Your laptop / jumpbox
   |  https://coder.example.com
   |    home: Pi-hole -> 192.168.1.50 (LAN)                    (optional)
   |    away: Cloudflare Tunnel -> http://192.168.1.50:7080    (optional)
   v
Coder VM (192.168.1.50)
 |-- coder           (Coder server, port 7080)
 |-- coder_postgres  (Coder database)
 |-- coder_traefik   (HTTPS front door, ports 80/443)
 `-- coder-<owner>-ansible-sandbox   <- workspace built by template "infra-lab"
      |  ansible-core 2.16.2 venv (same as work), Terraform, code-server
      |  Docker engine #2 inside (Docker-in-Docker)
      |-- rocky8      <- dev container (systemd)  = RHEL 8 test target
      |-- rocky9      <- dev container (systemd)  = RHEL 9 test target
      `-- ubuntu2204  <- dev container (systemd)  = Ubuntu 22.04 test target

Who builds what

What Built by
The VM Proxmox (by hand)
Coder server, Postgres, Traefik build_coder Ansible role
ansible-sandbox workspace template infra-lab = coder-lab/templates/infra-lab/
rocky8 / rocky9 / ubuntu2204 coder-lab/workspaces/ansible-sandbox/nodes/*/.devcontainer
Login (optional) authentik at auth.example.com

Where things are saved

  • build_coder role: my Ansible containers repo
  • Template, targets and inventory: a private GitHub repo, coder-lab

Before you start

authentik (optional)

I use authentik for single sign-on with MFA. It is optional: without it, skip this part and log in to Coder with its built-in username and password.

If you use it, check that these already exist:

  1. authentik is reachable at https://auth.example.com
  2. In authentik, the Coder provider has the redirect URI https://coder.example.com/api/v2/users/oidc/callback
  3. The authentik client ID and secret are in the build_coder role variables
  4. The build_coder defaults have:
    • build_coder_access_url: "https://coder.example.com"
    • CODER_OIDC_ISSUER_URL = https://auth.example.com/application/o/coder/

Why: Coder contacts authentik every time it starts. If authentik is unreachable, Coder will not start (it crash-loops).

Cloudflare Tunnel (optional)

If you want to reach Coder from outside your home, check that the Cloudflare Tunnel is running.

Step 1: Create the Coder VM

In Proxmox, create a VM named coder:

Setting Value Why
OS Ubuntu/Debian server
CPU 2 cores
Memory 4096 MiB (minimum) 1 GB froze the VM. Coder, workspace and targets use about 2 GB
Disk 20 GiB on local-lvm (LVM-Thin) thin = only uses what is written; grow later
IP 192.168.1.50 DNS (and the tunnel, if you use one) point here
Options QEMU Guest Agent: enabled

It must be a VM, not an LXC container. An unprivileged LXC refuses what Docker-in-Docker and systemd targets need (raising the core limit, cgroup changes, ulimit). A VM has its own kernel, so it works.

Inside the VM:

sudo apt install -y qemu-guest-agent
sudo systemctl enable --now qemu-guest-agent

Install Docker, then check:

docker ps
getent group docker

Step 2: DNS and remote access (optional)

Both parts of this step are optional. Pi-hole and Cloudflare are what I use in my homelab.

  • Without Pi-hole: the name coder.example.com still has to point to the VM. Use your own DNS server, or add a line to the hosts file on each computer that connects (192.168.1.50 coder.example.com).
  • Without Cloudflare Tunnel: Coder only works inside your home network.

Pi-hole (home path, optional)

Local DNS:

  • A record: coder.example.com -> 192.168.1.50

Optional but recommended (Pi-hole v6: Settings -> All settings -> Expert -> Miscellaneous -> misc.dnsmasq_lines):

address=/coder.example.com/192.168.1.50

Why: without it, Pi-hole forwards the IPv6 (AAAA) question to the internet and hands out Cloudflare’s IPv6 address. Windows prefers IPv6, so at home it sometimes takes the Cloudflare path instead of the LAN.

Cloudflare Tunnel (away path, optional)

Zero Trust -> Networks -> Tunnels -> your tunnel -> Public Hostname:

  • Hostname: coder.example.com
  • Service: HTTP -> 192.168.1.50:7080

Do not put Cloudflare Access in front of Coder. VS Code Desktop and the coder CLI cannot complete a Cloudflare login page. authentik (with MFA), or Coder’s own login if you skip authentik, protects Coder.

Step 3: Install Coder with the build_coder role

Run the build_coder playbook against the Coder VM.

The role takes care of:

  • The Docker socket group ID: detected automatically (build_coder_docker_sock.stat.gid)
  • The access URL: build_coder_access_url

Expect failed=0 in the PLAY RECAP. Then on the VM:

docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Image}}"

Expect coder, coder_postgres (healthy) and coder_traefik, all Up.

Check that Coder answers locally:

curl -sS --max-time 5 -o /dev/null -w '%{http_code}\n' http://127.0.0.1:7080/healthz

Expect 200.

Step 4: First login and accounts

Without authentik, only do item 1: the admin account you create is your login.

With authentik (optional), do all of it:

  1. Open https://coder.example.com in the browser -> “Setup admin account”
  2. Create the emergency account:
    • A username for the emergency account
    • Email: different from your authentik email
    • Password: long and random, saved in a password manager
  3. Sign out
  4. Sign in with authentik. This creates your daily account
  5. Sign out, sign in with the emergency account
  6. Admin settings -> Users -> your authentik user -> Roles (pencil) -> tick Owner -> save
  7. Sign out, sign in with authentik again. You are now Owner

Why: the emergency account is the break-glass key when authentik is down (password login, no authentik).

Step 5: Coder SSH key to GitHub

Every new Coder server makes a new key. Do this once per Coder server.

  1. Coder: avatar -> Account -> SSH Keys -> Copy (starts with ssh-ed25519)
  2. GitHub: avatar -> Settings -> SSH and GPG keys -> New SSH key
    • Title: coder-workspaces
    • Paste -> Add SSH key
  3. Delete any old coder-workspaces key from GitHub (it belongs to an old Coder server)

Why: the template clones the private coder-lab repo when the workspace starts.

Test it later inside the workspace. A plain ssh -T [email protected] says “Permission denied”. That is normal: the key is only given to git.

git ls-remote [email protected]:<github-user>/coder-lab.git | head -2

Step 6: Coder CLI on the jumpbox

curl -fsSL https://coder.example.com/install.sh | sh
coder login https://coder.example.com
coder config-ssh
  • coder login: open the URL and sign in (with authentik, if you use it)
  • coder config-ssh: adds coder.* hosts to ~/.ssh/config

Step 7: Create the template infra-lab

Option A: from the jumpbox (CLI)

git clone [email protected]:<github-user>/coder-lab.git ~/coder-lab
coder templates push infra-lab \
  --directory ~/coder-lab/templates/infra-lab \
  --name v1.0.0-initial \
  --message "Rebuild from coder-lab repo" \
  --yes

coder templates push creates the template if it does not exist, and publishes the files in the folder as the active version.

Option B: from the web UI

  1. Templates -> Create a template -> Docker Containers -> Continue
  2. Image: leave the default -> Continue
  3. Modules: code-server -> Continue -> Continue
  4. Display name Infra Lab, ID infra-lab -> Create Template
  5. Source Code -> Edit:
    • main.tf: select all, paste coder-lab/templates/infra-lab/main.tf
    • modules.tf: select all, paste coder-lab/templates/infra-lab/modules.tf (replace everything, or code-server appears twice and you get a duplicate module error)
  6. Build -> Success -> Publish, with a version name such as v1.0.0-initial

Version names: vMAJOR.MINOR.PATCH-short-description, using only letters, numbers, dots and dashes.

Step 8: Create the workspace ansible-sandbox

Templates -> Infra Lab -> Create Workspace -> name ansible-sandbox -> Create.

The first start takes a few minutes. By itself, it:

  • starts Docker engine #2 (with the cgroup init step)
  • installs uv, Python 3.11, the Ansible venv (work versions) and Terraform
  • installs code-server and the devcontainer CLI
  • clones coder-lab to /home/coder/coder-lab (git-clone module)
  • starts rocky8, rocky9 and ubuntu2204 (coder_devcontainer)

The dashboard shows main plus three dev containers, all green. (The main buttons hide under “Show parent apps” once dev containers exist.)

Step 9: Verify

Open the ansible-sandbox terminal (Workspaces list -> >_ button on the row, or from the jumpbox ssh coder.main.ansible-sandbox.<owner>).

The prompt must start with (ansible).

ansible --version | head -1        # ansible [core 2.16.2]
which ansible                      # /home/coder/.venv/ansible/bin/ansible
terraform version | head -1        # Terraform v1.17.2
docker ps --format '{{.Names}}'    # rocky8 rocky9 ubuntu2204
cd ~/coder-lab/workspaces/ansible-sandbox
ansible all -i inventory.yml -m ping

Expect pong from rocky8, rocky9 and ubuntu2204.

Check systemd in a target:

docker exec rocky9 systemctl is-system-running    # running (or degraded)

Done.

Daily use

Connecting

  • Browser: Workspaces list -> ansible-sandbox row -> middle square = code-server, >_ = terminal
  • Jumpbox: coder list, coder show ansible-sandbox
  • SSH name = coder.<agent>.<workspace>.<owner>
    • ssh coder.main.ansible-sandbox.<owner>
    • ssh coder.rocky9.ansible-sandbox.<owner>
  • VS Code Desktop into a target: Coder panel -> ansible-sandbox -> play button on the target. (Not the VS Code Dev Containers “Reopen in Container”; its upload never finished for me.)
  • The VS Code setting window.restoreWindows = none stops it reconnecting to the last server

After a VM reboot

  • coder, postgres and traefik come back by themselves
  • ansible-sandbox stays stopped: Start it from the dashboard, or run coder start ansible-sandbox

Targets

  • Rebuild a target only after changing its devcontainer.json
  • Grey dot = not running -> Rebuild (or docker start <name> in ansible-sandbox)

Git

  • The workspace clones coder-lab once. It does NOT pull later.
  • Get updates: cd ~/coder-lab && git pull
  • Template changes: edit in coder-lab, push to GitHub, then push to Coder (Step 7), then Update the workspace

Memory

  • Proxmox shows cache as “used”; ignore the orange bar
  • The real check on the VM: free -h, and look at available
  • Per container: docker stats --no-stream
  • The workspace is limited to 2.5 GB (memory = 2560 in main.tf). Rule: workspace limit = VM memory - about 1.3 GB

Rules learned the hard way

Problem Cause Fix (already in the template or this guide)
systemd targets exit 255 / RLIMIT_CORE / cgroups an unprivileged LXC refuses kernel changes the Coder host is a VM
overlay ... invalid argument overlay on overlay (Docker in Docker) a Docker volume at /var/lib/docker
/etc/init.d/docker: ulimit ... not permitted the init script raises limits start dockerd directly (start_docker script)
“Structure needs cleaning” in a systemd target processes in the workspace root cgroup cgroup init step in start_docker (same as docker:dind)
rocky8: future feature annotations is not defined ansible-core 2.22 needs Python 3.7+, Rocky 8 has 3.6 venv with ansible-core 2.16.2 on Python 3.11
Only one dev container shown / Rebuild exit status 1 several targets sharing one folder one folder per target and a coder_devcontainer per target
Targets have no systemd dev containers replace the start command with a sleep loop "overrideCommand": false
VM froze, “Under memory pressure” the VM had 1 GB 4 GB and a workspace memory limit
Coder 502 / crash loop (restarts=5) authentik unreachable when Coder starts (only if you use authentik) make sure authentik is reachable before Coder starts
Home laptop sometimes 502 / hangs Pi-hole hands out Cloudflare’s IPv6 address (only with Pi-hole and Cloudflare) the dnsmasq address= line (Step 2)
Work VPN: Coder unreachable the VPN uses the work DNS, so it takes the Cloudflare path (only with Cloudflare) the tunnel route must work (Step 2)

Troubleshooting commands

# Coder restarting? (on the VM)
docker inspect coder --format 'started={{.State.StartedAt}} restarts={{.RestartCount}}'
docker logs --since 3h coder 2>&1 | grep -iE "fatal|error" | tail -20

# Tunnel errors, only with Cloudflare (on the host that runs the cloudflared container)
docker logs --since 30m <tunnel-container> 2>&1 | grep -iE "coder|ERR" | tail -15

# Which address does my laptop get? (Windows PowerShell)
nslookup coder.example.com
curl.exe -4 -skI --max-time 10 https://coder.example.com
curl.exe -6 -skI --max-time 10 https://coder.example.com

# Inside ansible-sandbox from the VM (back door, works without Coder)
docker exec -it -u coder coder-<owner>-ansible-sandbox bash

Appendix: file contents

coder-lab layout

coder-lab/
 |-- templates/
 |    `-- infra-lab/
 |         |-- main.tf
 |         `-- modules.tf
 `-- workspaces/
      `-- ansible-sandbox/
           |-- inventory.yml
           `-- nodes/
                |-- rocky8/.devcontainer/devcontainer.json
                |-- rocky9/.devcontainer/devcontainer.json
                `-- ubuntu2204/.devcontainer/devcontainer.json

templates/infra-lab/modules.tf

module "code-server" {
  count                   = data.coder_workspace.me.start_count
  source                  = "registry.coder.com/coder/code-server/coder"
  version                 = "1.5.0"
  agent_id                = coder_agent.main.id
  additional_args         = ""
  auto_install_extensions = false
  extensions_dir          = ""
  folder                  = ""
  install_version         = ""
  offline                 = false
  open_in                 = "slim-window"
  port                    = 13337
  use_cached              = false
  use_cached_extensions   = false
  workspace               = ""
}

module "devcontainers-cli" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/coder/devcontainers-cli/coder"
  version  = "~> 1.0"
  agent_id = coder_agent.main.id
}

module "git-clone" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/coder/git-clone/coder"
  version  = "~> 2.0"
  agent_id = coder_agent.main.id
  url      = "[email protected]:<github-user>/coder-lab.git"
  base_dir = "/home/coder"
}

templates/infra-lab/main.tf

terraform {
  required_providers {
    coder = {
      source = "coder/coder"
    }
    docker = {
      source = "kreuzwerker/docker"
    }
  }
}

locals {
  username = data.coder_workspace_owner.me.name
}

variable "docker_socket" {
  default     = ""
  description = "(Optional) Docker socket URI"
  type        = string
}

provider "docker" {
  host = var.docker_socket != "" ? var.docker_socket : null
}

data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}

resource "coder_agent" "main" {
  arch           = data.coder_provisioner.me.arch
  os             = "linux"
  dir            = "/home/coder"
  startup_script = <<-EOT
    set -e

    # Prepare user home with default files on first start.
    if [ ! -f ~/.init_done ]; then
      cp -rT /etc/skel ~
      touch ~/.init_done
    fi

    # Activate the Ansible venv in every new terminal
    if ! grep -q ".venv/ansible/bin/activate" ~/.bashrc; then
      echo '[ -f ~/.venv/ansible/bin/activate ] && source ~/.venv/ansible/bin/activate' >> ~/.bashrc
    fi
  EOT

  env = {
    GIT_AUTHOR_NAME     = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
    GIT_AUTHOR_EMAIL    = "${data.coder_workspace_owner.me.email}"
    GIT_COMMITTER_NAME  = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name)
    GIT_COMMITTER_EMAIL = "${data.coder_workspace_owner.me.email}"
  }

  metadata {
    display_name = "CPU Usage"
    key          = "0_cpu_usage"
    script       = "coder stat cpu"
    interval     = 10
    timeout      = 1
  }

  metadata {
    display_name = "RAM Usage"
    key          = "1_ram_usage"
    script       = "coder stat mem"
    interval     = 10
    timeout      = 1
  }

  metadata {
    display_name = "Home Disk"
    key          = "3_home_disk"
    script       = "coder stat disk --path $${HOME}"
    interval     = 60
    timeout      = 1
  }

  metadata {
    display_name = "CPU Usage (Host)"
    key          = "4_cpu_usage_host"
    script       = "coder stat cpu --host"
    interval     = 10
    timeout      = 1
  }

  metadata {
    display_name = "Memory Usage (Host)"
    key          = "5_mem_usage_host"
    script       = "coder stat mem --host"
    interval     = 10
    timeout      = 1
  }

  metadata {
    display_name = "Load Average (Host)"
    key          = "6_load_host"
    script   = <<EOT
      echo "`cat /proc/loadavg | awk '{ print $1 }'` `nproc`" | awk '{ printf "%0.2f", $1/$2 }'
    EOT
    interval = 60
    timeout  = 1
  }

  metadata {
    display_name = "Swap Usage (Host)"
    key          = "7_swap_host"
    script       = <<EOT
      free -b | awk '/^Swap/ { printf("%.1f/%.1f", $3/1024.0/1024.0/1024.0, $2/1024.0/1024.0/1024.0) }'
    EOT
    interval     = 10
    timeout      = 1
  }
}

resource "docker_volume" "home_volume" {
  name = "coder-${data.coder_workspace.me.id}-home"
  lifecycle {
    ignore_changes = all
  }
  labels {
    label = "coder.owner"
    value = data.coder_workspace_owner.me.name
  }
  labels {
    label = "coder.owner_id"
    value = data.coder_workspace_owner.me.id
  }
  labels {
    label = "coder.workspace_id"
    value = data.coder_workspace.me.id
  }
  labels {
    label = "coder.workspace_name_at_creation"
    value = data.coder_workspace.me.name
  }
}

resource "docker_container" "workspace" {
  count      = data.coder_workspace.me.start_count
  image      = "codercom/enterprise-node:ubuntu"
  privileged = true
  memory     = 2560
  name       = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
  hostname   = data.coder_workspace.me.name
  entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
  env        = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
  host {
    host = "host.docker.internal"
    ip   = "host-gateway"
  }
  volumes {
    container_path = "/home/coder"
    volume_name    = docker_volume.home_volume.name
    read_only      = false
  }
  volumes {
    container_path = "/var/lib/docker"
    volume_name    = docker_volume.docker_volume.name
    read_only      = false
  }
  labels {
    label = "coder.owner"
    value = data.coder_workspace_owner.me.name
  }
  labels {
    label = "coder.owner_id"
    value = data.coder_workspace_owner.me.id
  }
  labels {
    label = "coder.workspace_id"
    value = data.coder_workspace.me.id
  }
  labels {
    label = "coder.workspace_name"
    value = data.coder_workspace.me.name
  }
}

resource "docker_volume" "docker_volume" {
  name = "coder-${data.coder_workspace.me.id}-docker"
  lifecycle {
    ignore_changes = all
  }
}

resource "coder_script" "start_docker" {
  count        = data.coder_workspace.me.start_count
  agent_id     = coder_agent.main.id
  display_name = "Start Docker"
  icon         = "/icon/docker.svg"
  run_on_start = true
  script       = <<-EOT
    #!/bin/sh
    # cgroup v2 nesting: move all processes into a child cgroup "init",
    # then let child cgroups use the controllers (same as docker:dind does)
    if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
      sudo sh -c '
        mkdir -p /sys/fs/cgroup/init
        xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || true
        sed -e "s/ / +/g" -e "s/^/+/" < /sys/fs/cgroup/cgroup.controllers > /sys/fs/cgroup/cgroup.subtree_control
      '
    fi
    nohup sudo dockerd > /tmp/dockerd.log 2>&1 &
  EOT
}

resource "coder_script" "install_ansible" {
  count        = data.coder_workspace.me.start_count
  agent_id     = coder_agent.main.id
  display_name = "Install Ansible (work versions)"
  run_on_start = true
  script       = <<-EOT
    #!/bin/sh
    VENV="$HOME/.venv/ansible"

    # uv: creates the venv and downloads Python 3.11
    if [ ! -x "$HOME/.local/bin/uv" ]; then
      pipx install uv
    fi

    # the venv: Python 3.11 + pinned versions
    if [ ! -x "$VENV/bin/ansible" ]; then
      "$HOME/.local/bin/uv" venv --python 3.11 "$VENV"
      "$HOME/.local/bin/uv" pip install --python "$VENV" \
        ansible==9.1.0 ansible-core==2.16.2 ansible-lint==24.5.0 \
        molecule==24.2.1 molecule-plugins==23.5.3 \
        docker==7.0.0 yamllint==1.35.1
    fi

    # remove the old pipx Ansible (latest version), so only the venv one exists
    pipx uninstall ansible 2>/dev/null || true
    pipx uninstall ansible-lint 2>/dev/null || true
  EOT
}

resource "coder_script" "install_terraform" {
  count        = data.coder_workspace.me.start_count
  agent_id     = coder_agent.main.id
  display_name = "Install Terraform"
  run_on_start = true
  script       = <<-EOT
    #!/bin/sh
    TF_VERSION="1.17.2"
    if [ ! -x "$HOME/.local/bin/terraform" ]; then
      mkdir -p "$HOME/.local/bin" /tmp/tf
      curl -fsSLo /tmp/tf/terraform.zip "https://releases.hashicorp.com/terraform/$${TF_VERSION}/terraform_$${TF_VERSION}_linux_amd64.zip"
      python3 -m zipfile -e /tmp/tf/terraform.zip /tmp/tf/
      mv /tmp/tf/terraform "$HOME/.local/bin/terraform"
      chmod +x "$HOME/.local/bin/terraform"
      rm -rf /tmp/tf
    fi
  EOT
}

resource "coder_devcontainer" "rocky8" {
  count            = data.coder_workspace.me.start_count
  agent_id         = coder_agent.main.id
  workspace_folder = "/home/coder/coder-lab/workspaces/ansible-sandbox/nodes/rocky8"
}

resource "coder_devcontainer" "rocky9" {
  count            = data.coder_workspace.me.start_count
  agent_id         = coder_agent.main.id
  workspace_folder = "/home/coder/coder-lab/workspaces/ansible-sandbox/nodes/rocky9"
}

resource "coder_devcontainer" "ubuntu2204" {
  count            = data.coder_workspace.me.start_count
  agent_id         = coder_agent.main.id
  workspace_folder = "/home/coder/coder-lab/workspaces/ansible-sandbox/nodes/ubuntu2204"
}

Notes on main.tf:

  • $${...} is escaped for Terraform; the shell receives ${...}
  • The activation line lives in startup_script (runs in order, after the /etc/skel copy), not in a coder_script (those run in parallel, and the skel copy could overwrite .bashrc)
  • No sudoers core-limit fix is needed on a VM

workspaces/ansible-sandbox/nodes/rocky9/.devcontainer/devcontainer.json

{
  "name": "rocky9",
  "image": "geerlingguy/docker-rockylinux9-ansible",
  "runArgs": [
    "--name", "rocky9",
    "--hostname", "rocky9",
    "--privileged",
    "--cgroupns=host",
    "-v", "/sys/fs/cgroup:/sys/fs/cgroup:rw"
  ],
  "overrideCommand": false,
  "remoteUser": "root",
  "updateRemoteUserUID": false
}

rocky8 and ubuntu2204 use the same file; change name, image, --name and --hostname:

  • rocky8: geerlingguy/docker-rockylinux8-ansible
  • ubuntu2204: geerlingguy/docker-ubuntu2204-ansible

Settings explained:

  • runArgs: systemd needs privileged mode, the host cgroup namespace and /sys/fs/cgroup mounted read-write
  • overrideCommand: false: keep the image’s start command (systemd); the default true runs a sleep loop
  • remoteUser: root, updateRemoteUserUID: false: skip the UID build step (not needed for a target)

workspaces/ansible-sandbox/inventory.yml

all:
  vars:
    ansible_connection: community.docker.docker
  children:
    rhel8:
      hosts:
        rocky8:
          ansible_python_interpreter: /usr/bin/python3
    rhel9:
      hosts:
        rocky9:
          ansible_python_interpreter: /usr/bin/python3.9
    ubuntu:
      hosts:
        ubuntu2204:
          ansible_python_interpreter: /usr/bin/python3
  • community.docker.docker: Ansible talks to the targets through docker exec, no SSH needed
  • Group ubuntu (not ubuntu2204): a group and a host with the same name confuses Ansible
  • Always run with -i inventory.yml here, so tests never touch real servers

Work versions (keep in sync with the work jumpbox)

Package Version
Python 3.11
ansible 9.1.0
ansible-core 2.16.2
ansible-lint 24.5.0
molecule 24.2.1
molecule-plugins 23.5.3
docker (SDK) 7.0.0
yamllint 1.35.1

Check at work: ansible --version | head -1 and pip list | grep -i ansible. If they change, update install_ansible in main.tf, push it, and delete ~/.venv/ansible in the workspace so it is rebuilt on the next start.