Rewriting Ansible roles from K8s operators

Seed idea (2026-10-03): take popular Kubernetes operators and use their reconcile logic as the base specification for better Ansible roles. The operator repos are the distilled, battle-tested procedures for running stateful software — election, failover, health checks, rolling upgrades, backup ordering — written as code by the experts of each system.

The transfer:

  • CRD schema → role defaults/interface. An operator’s CRD is the curated, validated configuration surface — every field is a decision the domain experts decided matters. Map it to role variables instead of the usual defaults-sprawl (a role exposing 80 vars nobody prioritized).
  • Reconcile loop → idempotent tasks + status verification. Operators converge from any state; most roles only handle the happy path from clean. Steal the convergence property: each handler checks observed vs desired, and the role re-runs safely from mid-failure states. The failover sections of an operator are literally a runbook for “things went wrong half-way”.
  • Status conditions → verification/assertion tasks. Operators report Ready, ReplicaSync, etc. — mirror those as post-task assertions with the same names, so the role fails loudly where the operator would keep reconciling.
  • Health criteria → check definitions. What the operator probes before declaring healthy is the domain-expert answer to “when is it actually up?” — better than wait_for: port=3306.

Reference operators to mine (already captured):

  • cloudnative-pg (OSS) — PG primary election, rolling updates, replication health; explicitly documents which DBA operations it automates.
  • mariadb-operator (OSS) — the topology decision tree (async vs Galera vs multi-cluster) with the operational consequences of each; mariadb-backup/VolumeSnapshot sequencing.
  • Candidates next: redis-operator, minio-operator, rabbitmq-cluster-operator, strimzi (Kafka) — the same pattern per system.

Related to the COT Ansible roles rewrite lane at work (~/projects/ansible-roles-rewrite; Kubernetes Operators is the pattern note; Working with legacy code is the migration discipline — old roles are legacy code too). The Strangler-Fig mechanics from Fearless refactoring apply directly: stand the new role version beside the old, migrate hosts one at a time.

Related: Kubernetes Operators · High Availability · Fearless refactoring · Infrastructure as Code