Hierarchical Data
The Choria Hierarchical Data Resolver is a small data resolver inspired by Hiera. It evaluates a YAML or JSON document alongside a set of facts to produce a final data map.
The resolver supports first and deep merge strategies and relies on expression-based string interpolation for hierarchy entries. It is optimized for single files that hold both hierarchy and data, rather than the multi-file approach common in Hiera.
Key features:
- Lookup expressions based on the Expr Language
- Type-preserving lookups (returns typed data, not just strings)
- Command-line tool with built-in system facts
- Go library for embedding
Usage
Here’s an annotated example:
The templating here is identical to that in the Template documentation, except only the lookup() function is available (no file access functions).
Default Hierarchy
If no hierarchy section is provided, the resolver uses a default hierarchy of ["default"].
CLI Example
The ccm hiera command resolves hierarchy files with facts. It is designed to be a generally usable tool, with flexible options for providing facts.
Given the input file data.json:
Resolve with facts provided on the command line:
Output formats:
Fact Sources
Facts can come from multiple sources, which are merged together:
System facts (-S or --system-facts):
Environment variables as facts (-E or --env-facts):
Facts file (--facts FILE):
Command-line facts (key=value pairs):
All fact sources can be combined. Command-line facts take highest precedence.
Data in NATS
NATS is a lightweight messaging system that supports Key-Value stores. Hierarchy data can be stored in NATS and used with ccm ensure and ccm hiera commands.
To use NATS as a hierarchy store, configure a NATS context for authentication:
Create a KV store and add your hierarchy data:
Resolve the hierarchy using the KV store:
Data on Web Servers
Hierarchy data can also be stored on a web server and fetched via HTTP or HTTPS.
HTTP Basic Auth is supported via URL credentials: