Ansible k8s module and Kubernetes API: merging custom facts into resource metadata
0 reputation · 10 Feb 2021, 20:44 UTC
Ansible k8s module and Kubernetes API: merging custom facts into resource metadata
When using the k8s module to create or update resources, I want to ensure that custom facts gathered by Ansible are merged into the resource’s labels and annotations without overwriting existing metadata set by other tools or by the cluster itself.
Key constraints include maintaining idempotency across multiple playbook runs, avoiding race conditions in concurrent deployments, and ensuring compatibility between the module’s version and the target cluster’s Kubernetes API version. The module documentation states that labels and annotations are merged, but it does not clarify how conflicts are resolved when the same key exists in both the fact and the resource.
Unresolved questions:
- How does the
k8smodule handle label or annotation keys that exist in both the custom fact and the existing resource metadata? - Does the module provide an option to prioritize fact‑derived values over existing ones, or vice versa, and if so, how is that configured?
- What is the documented behavior when a playbook is run in check mode versus apply mode regarding these merges?