This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an Ansible role for deploying NetBox (network infrastructure management application) as a Docker Compose project. The role handles installation, configuration, plugin management, and optional custom builds of the NetBox container.
The main task flow (tasks/main.yml) executes in this order:
- validate.yml - Validates role variables and prerequisites
- setup.yml - Creates directory structure, templates configuration files
- plugins.yml - Handles NetBox plugin installation from PyPI or git sources
- system.yml - Sets up system-level requirements (directories, permissions)
- build.yml - (Conditional) Builds custom NetBox Docker image when
netbox_docker_build: true - Finally launches the Docker Compose project using
community.docker.docker_compose_v2
Configuration Templates (templates/):
docker-compose.yml.j2- Main orchestration file (netbox, postgres, redis, redis-cache, optional caddy)Dockerfile.j2- Custom NetBox image with plugins and extra packagesenv/*.env.j2- Environment variables for each service (netbox, postgres, redis, redis-cache, pgbackups)configuration/extra.py.j2- NetBox Django configuration extensions (ADMINS, logging, extra config)configuration/plugins.py.j2- NetBox plugin configuration (PLUGINS, PLUGINS_CONFIG)Caddyfile.j2- TLS reverse proxy configuration
Build System:
- When
netbox_docker_build: true, clones netbox-docker repository and runs its build script - When plugins or extra packages are specified,
netbox_force_dockerfile_buildtriggers a custom Dockerfile build - Build distinguishes between upstream image builds vs. custom Dockerfile-based builds
Volume Management:
- Default volumes defined in
vars/main.yml: reports, scripts, media, static - Additional volumes can be specified via
netbox_volumesvariable - Volume paths map to container paths inside
/opt/netbox/netbox/
Build Control:
netbox_docker_build- Build from netbox-docker source (full build)netbox_force_dockerfile_build- Use Dockerfile.j2 for plugins/packages- Auto-set when
netbox_pluginsornetbox_extra_packagesare defined
Versions:
netbox_netbox_version- NetBox application version (e.g., 4.5.1)netbox_netbox_docker_version- netbox-docker wrapper version (e.g., 4.0.0)- Combined as:
v{netbox_version}-{docker_version}for image tags
Secrets (auto-generated with ansible.builtin.password lookup):
netbox_secret_key- Django secret key (50 chars)netbox_pg_password- PostgreSQL passwordnetbox_valkey_password- Valkey (Redis) passwordnetbox_valkey_cache_password- Valkey cache password- Stored in
/tmp/with seed based on inventory_hostname
Plugins:
netbox_plugins- List of dicts:{name, src (optional), version (optional)}netbox_plugins_config- Dict mapping plugin names to their config dicts- Installed via pip or git clone during Dockerfile build
# Syntax check
ansible-playbook example-playbook.yml --syntax-check
# Run with check mode (dry run)
ansible-playbook example-playbook.yml --check
# Run against localhost
ansible-playbook example-playbook.yml -i localhost, --connection=localFor testing TLS locally, use mkcert:
mkcert -install
mkcert localhost 127.0.0.1 ::1Then reference certificates in playbook vars:
netbox_use_caddy: true
netbox_ssl_cert_bundle: /path/to/localhost+2.pem
netbox_ssl_cert_key: /path/to/localhost+2-key.pemAdding a new template: Place in templates/, reference in tasks/setup.yml
Modifying docker-compose structure: Edit templates/docker-compose.yml.j2, ensure environment files in templates/env/ are updated
Adding new configuration options:
- Add default value in
defaults/main.yml - Add to appropriate template (usually
netbox.env.j2orconfiguration/extra.py.j2) - Document in README.md variables table
Testing plugin installation:
Set netbox_plugins in playbook, role will automatically trigger Dockerfile build and install plugins during image build.
.
├── defaults/main.yml # All configurable variables with defaults
├── vars/main.yml # Internal variables (container paths, UID)
├── tasks/
│ ├── main.yml # Orchestrates task execution
│ ├── validate.yml # Variable validation
│ ├── setup.yml # Template rendering, directory creation
│ ├── plugins.yml # Plugin management
│ ├── system.yml # System-level setup
│ └── build.yml # Custom image building
├── templates/
│ ├── docker-compose.yml.j2 # Main compose file
│ ├── Dockerfile.j2 # Custom build with plugins
│ ├── configuration/ # NetBox configuration templates
│ │ ├── extra.py.j2 # Django extra config (ADMINS, logging)
│ │ └── plugins.py.j2 # Plugin configuration
│ ├── env/ # Environment variable templates
│ └── *.j2 # Other config templates
└── meta/main.yml # Role metadata
Required collections:
community.docker- For docker_compose_v2 moduleansible.posix- For mount, sysctl modules (if used)
Required on target host:
- Docker Engine
- Docker Compose V2 (as docker compose plugin)
master- Main branch (stable releases)develop- Current development branch- PRs should target
developbranch by default
IMPORTANT: Under absolutely no circumstances should code attributions be added to commit messages. Do not include any "Generated with Claude Code" or similar attributions in commits.