requires_ansible and every role's min_ansible_version said 2.19, which CI never tested; CI tests only the pinned ansible-core (2.22). The floor now equals that minor. ansible-lint 26.10.1's built-in supported list ends at 2.19, so .ansible-lint adds 2.22 for meta-runtime[unsupported-version]. BREAKING CHANGE: ansible-core 2.19, 2.20 and 2.21 (and controller Python 3.12) are no longer supported. Closes #164 Assisted-by: Claude Code
gitea_runner
Installs a Gitea Actions runner (gitea-runner) with Docker as a systemd service, registers it against a Gitea instance with a token minted on the gitea_runner_token_host, renders its config.yaml, optionally schedules a Docker prune, optionally adds a host-executor label for jobs that use the host's Docker daemon, and optionally updates or removes the runner. Variables and their types are defined in meta/argument_specs.yml, which is the source of truth.
Supported platforms
Ubuntu 24.04 (noble), the image the molecule scenario runs on. The role uses ansible.builtin.apt and installs docker.io, so Debian-family hosts only, and needs outbound access to dl.gitea.com and Docker Hub (the Docker check pulls ubuntu:24.04). On an unprivileged LXC host, Docker needs nesting enabled on the container.
Requirements and run order
- Use it by its fully qualified name,
mortis.kamino.gitea_runner. - Hard dependency on the token host:
tasks/mint_token.ymldelegatesgitea actions generate-runner-tokento the inventory host named bygitea_runner_token_host. That host must be in the inventory and must already have Gitea installed (for example bymortis.kamino.gitea), withapp.iniin place. A first install of the runner fails when it is down or has no Gitea. Registration only runs when<gitea_runner_work_dir>/.runnerdoes not exist, so later runs do not need it. Under--checkthe registration is reported and not run. - Registration inputs:
gitea_runner_token_host,gitea_runner_instance_urlandgitea_runner_namehave empty role defaults and are asserted non-empty only intasks/mint_token.yml, so a run that never registers is not blocked. - Keep in step with the Gitea installation on the token host: the delegated command uses
gitea_runner_gitea_user,gitea_runner_gitea_install_dirandgitea_runner_gitea_app_dir(defaultsgit,/usr/local/bin,/etc/gitea, the same as the defaults ofmortis.kamino.gitea). They are separate variables from thegitearole's: changing thegitearole's values on the token host does not change these, and registration then runs the wrong path or user there. Set both. - The registration token is generated on the fly, held in a
no_logfact and passed togitea-runner registerthrough theGITEA_RUNNER_REGISTRATION_TOKENenvironment variable, not argv. It is never written to a file by the role. - The role creates
gitea_runner_groupandgitea_runner_userwhen they are missing; an existing account (for example the SSH login user) is reused. - Docker is installed by this role (
tasks/docker.yml) on first install, not bymortis.kamino.docker. - Fact gathering must be on for
gitea_runner_force_register: the backup name usesansible_date_time. - Updates: the update path stages the verified binary and hands the swap to
mortis.kamino._binary_update, an internal role of this Collection. gitea_runner_versionis asserted at role start to be a plainX.Y.Zrelease number, with no leadingv. Pin it in inventory to move the runner independently of Collection releases; the role default changes only with a release.- The executor and job image of a job come from its label's suffix (
:hostordocker://<image>); a label with no suffix runs its jobs on the host.config.yamlhas no keys for them.
Role variables
| Variable | Default | Description |
|---|---|---|
gitea_runner_remove |
false |
Stop and disable the service, remove the unit, the binary and the Docker prune units. The role ends there: nothing is installed or registered in the same run, and the runner is not deregistered in Gitea. |
gitea_runner_remove_data |
false |
With gitea_runner_remove, also delete the work directory, including the registration. |
gitea_runner_force_register |
false |
Mint the token first (a failed mint stops before anything is touched), then back up .runner, stop the service, remove .runner and register again with the current gitea_runner_instance_url and gitea_runner_registration_scope; configure starts the service. Only the newest backup is kept. Refused when GITHUB_ACTIONS, GITEA_ACTIONS or CI is set on the controller; under --check nothing is removed or registered. |
gitea_runner_update |
false |
Run the update tasks when the installed version differs from gitea_runner_version: download and verify to a staging path, then mortis.kamino._binary_update stops, backs up, swaps, restarts, checks the version and rolls back on failure. |
gitea_runner_version |
pinned in defaults/main.yml |
Release to install, X.Y.Z. |
gitea_runner_download_url |
dl.gitea.com, linux amd64 (templated) | Binary URL. |
gitea_runner_checksum_url |
dl.gitea.com .sha256 (templated) |
Checksum file the runner binary is verified against (sha256) on install and update; it must list the file name of gitea_runner_download_url. |
gitea_runner_user / gitea_runner_group |
gitea-runner / gitea-runner |
Daemon account; the user joins the docker group. |
gitea_runner_home |
/home/gitea-runner |
Home of the daemon account. |
gitea_runner_install_dir |
/usr/local/bin |
Binary directory. |
gitea_runner_work_dir |
/var/lib/gitea-runner |
Registration file and config.yaml. Not passed to the runner as a job work directory: jobs use the upstream defaults. |
gitea_runner_service_unit |
/etc/systemd/system/gitea-runner.service |
Unit path. |
gitea_runner_name |
empty (asserted when registering) | Registered runner name. |
gitea_runner_instance_url |
empty (asserted when registering) | Instance to register against. |
gitea_runner_token_host |
empty (asserted when registering) | Inventory host that mints the registration token. |
gitea_runner_registration_scope |
empty (instance-wide) | --scope of the token: an owner (user or organisation) or owner/repo. Format asserted at role start; read only when registering. |
gitea_runner_gitea_install_dir |
/usr/local/bin |
Gitea binary directory on the token host. |
gitea_runner_gitea_user |
git |
User of the delegated command on the token host. |
gitea_runner_gitea_app_dir |
/etc/gitea |
app.ini directory on the token host. |
gitea_runner_log_level |
info |
log.level. |
gitea_runner_capacity |
1 |
runner.capacity, concurrent jobs. |
gitea_runner_labels |
docker, ubuntu-lxc |
Workflow labels; the molecule label is appended when enabled. |
gitea_runner_container_privileged |
false |
container.privileged. |
gitea_runner_container_docker_host |
unix:///var/run/docker.sock |
container.docker_host; - keeps the socket out of job containers. |
gitea_runner_container_volumes |
none (commented example in defaults) | Extra job container mounts; the key is omitted when undefined. |
gitea_runner_docker_prune_enabled |
false |
Weekly systemd timer that prunes Docker data; skipped while a job container runs. |
gitea_runner_docker_prune_schedule |
Sun *-*-* 04:30:00 |
OnCalendar of the prune timer. |
gitea_runner_docker_prune_container_age, _image_age |
24h, 168h |
until filters (creation time) for containers, and for images and build cache. |
gitea_runner_docker_prune_job_max_age |
21600 |
Seconds; the prune skips while a younger container runs and ignores older ones as leaked job containers. |
gitea_runner_docker_prune_keep_per_repository |
0 (off) |
Newest image IDs kept per repository by the weekly and pressure prunes; every other image no container uses is removed. A multi-tag image counts once. |
gitea_runner_docker_prune_disk_threshold_percent |
0 (off) |
Use % of the Docker root's filesystem above which the pressure prune runs the count prune and a capped builder prune, behind the job gate. 1 to 99; needs the count above 0. |
gitea_runner_docker_prune_disk_check_schedule |
hourly |
OnCalendar of the pressure prune timer. |
gitea_runner_docker_prune_builder_keep_storage |
10GB |
--keep-storage of the builder prune under pressure. |
gitea_runner_molecule_enabled |
false |
Add the host label and install git and python3, which a job on it uses on the host; the job brings its own toolchain in an image and runs it on the host's Docker daemon. |
gitea_runner_molecule_label |
molecule |
Host-executor label name, registered as <label>:host. |
Tags
gitea_runner (everything), remove, prereqs, docker, install, register, configure, health, update, molecule, prune. The input asserts and the prereqs tasks are also tagged always.
Example play
- name: Install a Gitea Actions runner
hosts: runners
roles:
- role: mortis.kamino.gitea_runner
vars:
gitea_runner_instance_url: https://git.example.com/
gitea_runner_token_host: git-server
gitea_runner_name: runner-1
gitea_runner_capacity: 2
The play needs the token host in the inventory with Gitea installed.
Update with -e gitea_runner_update=true. Remove with -e "gitea_runner_remove=true gitea_runner_remove_data=true".
Change the registration scope of a registered runner: set gitea_runner_registration_scope, then run the play by hand, not from CI, with -e gitea_runner_force_register=true. A plain run never re-registers, because .runner exists. The token is minted before .runner is touched, so a bad scope or an unreachable token host leaves the current registration running. Afterwards, in Site Administration → Actions → Runners: delete the old runner entry, now offline (a leftover copy of the old .runner would still authenticate against it), and reset the instance-wide registration token (the CLI returns the latest active one, so the old token stays valid and could register a new instance-wide runner). Confirm GITEA_RUNNER_REGISTRATION_TOKEN is not set in the Gitea server's environment.
Tests
The default molecule scenario runs without a Gitea server and without Docker: a stub docker.service, a stub runner binary and a seeded .runner stand in for them, and the downloads come from local file:// URLs. It covers the converge with the prune timer and an update through _binary_update (and its idempotence), the rendered config.yaml and unit, the prune gate script, the count prune and the disk check against a stub docker CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the host packages of the host-executor label are not covered.
Notes
- Idempotent: yes.
- The role is not a state selector.
main.ymlalways runs prerequisites and configure unlessgitea_runner_removeis true; Docker and the binary install only when the binary is absent; registration only when.runneris absent (orgitea_runner_force_registerremoved it); remove only whengitea_runner_removeis true, and then every later task is skipped. - Trust: with
gitea_runner_molecule_enabled, jobs on the host-executor label run as the runner user, who is in thedockergroup, so they are root-equivalent on the runner host, which holds the registration and the secrets of every job it runs. Anyone who can run a workflow on that label can use it. Enable it only on a host whose registration scope (gitea_runner_registration_scope) is limited to repositories whose pushers you trust, and keep the job secrets of other repositories off that runner. - The runner binary is verified against
gitea_runner_checksum_urlon install and update; a mismatch fails the download task, and on an update leaves the running binary in place. - Handlers:
Restart Gitea Runnerruns when the config template changes or a registration happens. - The Docker prune units (
gitea-runner-docker-prune.{service,timer}) are written only whilegitea_runner_docker_prune_enabledis true. Setting it back to false leaves them in place: runsystemctl disable --now gitea-runner-docker-prune.timerby hand.gitea_runner_removedeletes them, the pressure units and the prune scripts. A run skipped because a job was running is not retried until the next timer elapse: shortengitea_runner_docker_prune_schedule(e.g.*-*-* 04:30:00) if that happens. - The pressure prune (
gitea-runner-docker-prune-pressure.{service,timer}) runs once per check while usage is above the threshold; it has no low watermark, so usage that stays high needs a smaller count or a larger disk. A threshold set back to0stops its timer and removes its units and the disk check script. The age prunes and the count prune both apply: an image either one removes is gone. - The play fails when
gitea-runneris notactiveafter start. no_logcovers the token mint, the token fact and the registration command.