aboutsummaryrefslogtreecommitdiff
path: root/content/blog/cfengine
diff options
context:
space:
mode:
authorJulien Dessaux2023-04-23 22:33:49 +0200
committerJulien Dessaux2023-04-23 22:34:10 +0200
commitea435049b3a3f5057b3a894040df3cf4f3256d9e (patch)
tree9046430870fa050e6568fcfbe409f8a8d295d0b3 /content/blog/cfengine
parentDocument the second gotosocial backup job (diff)
downloadwww-ea435049b3a3f5057b3a894040df3cf4f3256d9e.tar.gz
www-ea435049b3a3f5057b3a894040df3cf4f3256d9e.tar.bz2
www-ea435049b3a3f5057b3a894040df3cf4f3256d9e.zip
Refactored syntax highlighting shortcodes into markdown
Diffstat (limited to '')
-rw-r--r--content/blog/cfengine/leveraging-yaml.md18
1 files changed, 9 insertions, 9 deletions
diff --git a/content/blog/cfengine/leveraging-yaml.md b/content/blog/cfengine/leveraging-yaml.md
index e773325..494a41c 100644
--- a/content/blog/cfengine/leveraging-yaml.md
+++ b/content/blog/cfengine/leveraging-yaml.md
@@ -17,7 +17,7 @@ The use case bellow lacks a bit or error control with argument validation, it wi
In `cmdb/hosts/andromeda.yaml` we describe some properties of a host named andromeda:
-{{< highlight yaml >}}
+```yaml
domain: adyxax.org
host_interface: dummy0
host_ip: "10.1.0.255"
@@ -35,13 +35,13 @@ tunnels:
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 :
-{{< highlight yaml >}}
+```yaml
bundle common g
{
vars:
@@ -51,14 +51,14 @@ bundle common g
any::
"has_host_data" expression => fileexists("$(sys.inputdir)/cmdb/hosts/$(sys.host).yaml");
}
-{{< /highlight >}}
+```
## Using the data
### Cfengine agent bundle
We access the data using the global g.host_data variable, here is a complete example :
-{{< highlight yaml >}}
+```yaml
bundle agent openvpn
{
vars:
@@ -91,7 +91,7 @@ bundle agent openvpn
"$(this.bundle): common.key repaired" ifvarclass => "openvpn_common_key_repaired";
"$(this.bundle): $(tunnels) service repaired" ifvarclass => "tunnel_$(tunnels)_service_repaired";
}
-
+
bundle agent openvpn_tunnel(tunnel)
{
classes:
@@ -117,12 +117,12 @@ bundle agent openvpn_tunnel(tunnel)
"$(this.bundle): $(tunnel).conf repaired" ifvarclass => "openvpn_$(tunnel)_conf_repaired";
"$(this.bundle): $(tunnel) service repaired" ifvarclass => "tunnel_$(tunnel)_service_repaired";
}
-{{< /highlight >}}
+```
### Template file
Templates can reference the g.host_data too, like in the following :
-{{< highlight cfg >}}
+```cfg
[%CFEngine BEGIN %]
proto udp
port $(g.host_data[tunnels][$(openvpn_tunnel.tunnel)][port])
@@ -152,7 +152,7 @@ group nogroup
remote $(g.host_data[tunnels][$(openvpn_tunnel.tunnel)][remote_host]) $(g.host_data[tunnels][$(openvpn_tunnel.tunnel)][remote_port])
[%CFEngine END %]
-{{< /highlight >}}
+```
## References
- https://docs.cfengine.com/docs/master/examples-tutorials-json-yaml-support-in-cfengine.html