Packaging Your Own Ansible Roles as a Private Galaxy Collection
A shared Ansible collection replaced real copy-paste drift across every LXC template - but the version field it ships with hasn't moved since the day it was created.
Table of contents
Every service in this homelab starts the same way: a fresh LXC gets cloned from a template, and an Ansible playbook runs before anything else happens. For a long time, the roles that playbook called lived awkwardly - copy-pasted into each new template repo, drifting independently, fixed in one place and quietly stale everywhere else. The fix wasn't a smarter playbook. It was changing what the roles actually are: not files scattered across repos, but a single Ansible collection, versioned and installed like any other dependency.
Why a collection instead of copy-paste
The repo holding these roles isn't a playbook repo. It has a galaxy.yml at its root declaring a namespace and collection name, and a roles/ directory underneath - the two things that turn a folder of tasks into something ansible-galaxy recognizes as an installable package. That's the real difference between "a directory another repo happens to reference" and "a dependency a downstream repo installs."
Every LXC template clone points at it the same way, through a requirements.yml entry naming the collection's git URL:
collections:
- name: <internal-gitea>/brandon/ansible-roles.git
type: git
version: main # or a tag, once releases are taggedansible-galaxy collection install -r requirements.yml -p collections pulls it down before the playbook runs. Once installed, roles get called by their fully-qualified collection name - brandon.homelab.netbox_register, not just netbox_register - which is really just Ansible's version of a package import path. A self-hosted Gitea repo stands in perfectly well for a private Automation Hub here; nothing about the mechanism cares that the far end isn't galaxy.ansible.com.
What's actually in it, and why
The collection isn't a grab-bag. Each role earned its spot because more than one downstream service needed the identical behavior: registering a new host in NetBox, pointing a box at the internal apt-cacher proxy, deploying Pi-hole, installing Claude Code, shipping journald logs to the central log store. Centralizing them means a fix lands once instead of N times.
The claude_code role is a good concrete example of why that matters. It originally installed the package with Ansible's built-in get_url module - straightforward, until a Python 3.12+ change to how cert_file gets validated broke that download path on newer base images. The fix wasn't a workaround buried in one template repo; it was a one-line change in the shared role, swapping get_url for a plain curl invocation, and every consumer of the collection picked it up on its next run without anyone touching a downstream repo at all. That's the whole pitch for a shared collection in one commit.
The version nobody bumps
galaxy.yml declares a version field, same as any packaged dependency. In practice it's been touched exactly once since the collection was created - the commit that added the file in the first place. Every role added since then - apt_proxy, a netbox_register fix, the newer vlogs_forward role - shipped without the version number moving at all. It still reads 1.3.1, pinned to nothing.
That's not an oversight so much as an honest reflection of how the collection is actually consumed: every template repo's requirements.yml points at version: main, with a comment admitting the real plan ("or a tag, once releases are tagged") has never actually happened. Nothing forces the version field to mean anything when every consumer tracks the branch instead of a release. The documented workflow and the practiced one have quietly diverged, and for a single-maintainer homelab, that gap hasn't caused a single real problem yet - which is exactly the kind of thing that's easy to leave alone until the day it does.
What's still missing
The one real gap: there's no CI running against the collection itself. A bad Jinja template or a typo'd module name in any role would only surface downstream, hours or days later, on whatever LXC happens to install that collection next - not at the point the mistake was actually made. Adding a minimal lint/syntax-check workflow against the collection's own repo is the obvious next step, and it's tracked as an open item rather than something that's shipped yet.
None of this makes the collection pattern wrong. It replaced real, measurable copy-paste drift with a single source of truth, and the fixes it's already paid for - the cert_file bug chief among them - are worth more than a tidy version number. But "versioned" and "actually tracking a version" turned out to be two different claims, and it's worth being honest about which one is actually true today.