Sandbox – local testing¶
sandbox/ contains a Docker-based environment for testing playbooks against a throwaway container instead of a real server. Use it to validate changes before applying them to staging or production.
How it works¶
sandbox/init.sh does the following on every run:
- Generates a temporary ed25519 SSH key pair.
- Tears down and removes any existing container (and its local image).
- Builds and starts a fresh container with the temporary public key injected.
- Waits for SSH to be ready on
127.0.0.1:2222. - Runs
ansible-playbookagainst the container.
The container is a plain Ubuntu image with sshd and sudo configured. It mimics a fresh server.
Some roles are disabled in sandbox mode because they require external services or elevated system access that is not available in a container: - auditd_enabled: false - cadvisor_enabled: false - cloudflare_enabled: false
Basic usage¶
Run the default playbook (site.local.yml) against the local container:
Examples¶
Run a specific playbook¶
Dry run (check mode)¶
Run a single role¶
Use a real inventory (prod/stage) instead of local¶
Useful when you need real host variables (e.g. to test Cloudflare config):
Note: Ansible will still connect to the local container – the inventory is used only to load variables for the specified host.
Run a specific playbook against a real inventory host¶
Limitations¶
--roleand--playbookcannot be combined (the script will error).- The container does not persist between runs – every
init.shcall starts fresh. - Roles that call external APIs (Cloudflare) will still make real API calls if not disabled.
Docker files¶
sandbox/
├── init.sh # Entry point
└── docker/
├── Dockerfile # Ubuntu image with sshd + sudo
└── docker-compose.yml # Exposes port 2222 → 22
The SSH port is fixed at 2222 on the host. Make sure nothing else is bound to that port before running.