CFEngine has core support for JSON and YAML. You can use this support to read, access, and merge JSON and YAML files and use these to keep policy files internal and simple. You
access the data using the usual cfengine standard primitives.
The use case bellow lacks a bit or error control with argument validation, it will fail miserably if the YAML file is invalid.
## Example yaml
In `cmdb/hosts/andromeda.yaml` we describe some properties of a host named andromeda:
{{<highlightyaml>}}
domain: adyxax.org
host_interface: dummy0
host_ip: "10.1.0.255"
tunnels:
collab:
port: 1195
ip: "10.1.0.15"
peer: "10.1.0.14"
remote_host: collab.example.net
remote_port: 1199
legend:
port: 1194
ip: "10.1.0.3"
peer: "10.1.0.2"
remote_host: legend.adyxax.org
remote_port: 1195
{{</highlight>}}
## Reading the yaml
I am bundling the values in a common bundle, accessible globally. This is one of the first bundles processed in the order my policy files are loaded. This is just an extract, you can load multiple files and merge them to distribute common
settings :
{{<highlightyaml>}}
bundle common g
{
vars:
has_host_data::
"host_data" data => readyaml("$(sys.inputdir)/cmdb/hosts/$(sys.host).yaml", 100k);