Files
Kamino/roles/cloudflared/tasks/validate.yml
T
Defame1297 e308683431 feat(cloudflared): add the cloudflared role
Installs cloudflared as a systemd service for a locally managed
Cloudflare Tunnel: checks that the tunnel exists, manages its proxied
CNAMEs, renders config.yml and the credentials file, and updates the
binary through the internal _binary_update role. The opt-in mint entry
point creates the tunnel and registers its id and credentials as no_log
facts for the calling play to persist.

Validation runs first under always and asserts the tunnel secrets with
the mint instructions; the secrets stay optional in the argument spec on
purpose. cloudflared_manage_dns lets the records be managed elsewhere.
A removal now ends the role.

Assisted-by: Claude Code:claude-opus-5-5
2026-11-23 14:22:16 +00:00

82 lines
3.6 KiB
YAML

---
# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any
# change, whatever tags the run selects.
- name: Require a plain cloudflared_version
ansible.builtin.assert:
that:
- cloudflared_version is string
- cloudflared_version is match('^[0-9]{4}\\.[0-9]+\\.[0-9]+$')
fail_msg: >-
cloudflared_version must be a release tag such as 2026.11.1 (YYYY.M.P), with no leading v: it is
used in the download URL and compared with what the binary reports.
quiet: true
- name: Require a sha256 for the binary
ansible.builtin.assert:
that:
- cloudflared_sha256_amd64 is string
- cloudflared_sha256_amd64 is match('^[0-9a-fA-F]{64}$')
fail_msg: >-
cloudflared_sha256_amd64 must be the 64-digit hex sha256 of the cloudflared-linux-amd64 asset of
release {{ cloudflared_version }}.
quiet: true
# The items land in config.yml and, with cloudflared_manage_dns, become DNS records.
- name: Require a hostname and a service for every ingress rule
ansible.builtin.assert:
that:
- cloudflared_ingress is sequence
- cloudflared_ingress is not string
- cloudflared_ingress is not mapping
- cloudflared_ingress | reject('mapping') | list | length == 0
- cloudflared_ingress | selectattr('hostname', 'defined') | selectattr('service', 'defined') | list | length == cloudflared_ingress | length
fail_msg: >-
cloudflared_ingress must be a list of mappings, each with hostname and service (and optionally
originRequest).
quiet: true
# The role never creates the tunnel on its main entry point. Defined and empty (or null) counts
# as missing, as in the mint entry point, so the two cannot disagree.
- name: Require the minted tunnel secrets
ansible.builtin.assert:
that:
- cloudflared_tunnel_id | default('', true) | string | length > 0
- cloudflared_credentials_json | default('', true) | string | length > 0
fail_msg: >-
cloudflared_tunnel_id and cloudflared_credentials_json are not defined or empty: run the mint entry
point first (include_role with tasks_from: mint and -e cloudflared_mint_confirm=true), persist
cloudflared_minted_tunnel_id and cloudflared_minted_credentials_json into your inventory as these two
variables, and run the role again.
quiet: true
when: not (cloudflared_remove | bool)
# Every Cloudflare call below needs them: the tunnel check on every run, the tunnel deletion
# of a removal with cloudflared_remove_data.
- name: Require the Cloudflare API credentials
ansible.builtin.assert:
that:
- cloudflared_account_id | default('', true) | string | length > 0
- cloudflared_tunnel_api_token | default('', true) | string | length > 0
fail_msg: >-
cloudflared_account_id and cloudflared_tunnel_api_token (vaulted) have no role default and must be set
and non-empty.
quiet: true
when: >-
not (cloudflared_remove | bool) or
((cloudflared_remove_data | bool) and (cloudflared_tunnel_id | default('', true) | string | length) > 0)
- name: Require the zone while the role manages DNS
ansible.builtin.assert:
that:
- cloudflared_zone_name is string
- cloudflared_zone_name | length > 0
fail_msg: >-
cloudflared_manage_dns is true, so cloudflared_zone_name must name the DNS zone of the
cloudflared_ingress hostnames.
quiet: true
when:
- cloudflared_manage_dns | bool
- >-
not (cloudflared_remove | bool) or
((cloudflared_remove_data | bool) and (cloudflared_tunnel_id | default('', true) | string | length) > 0)