You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the yaml input provided in var.hieradata is invalid, Puppet will be unable to execute properly. We can prevent injecting invalid yaml by trying to first decode it using yamldecode in the validation block of var.hieradata.
validation {
condition = can(yamldecode(var.hieradata))
error_message = "Hieradata needs to be valid YAML"
}
The text was updated successfully, but these errors were encountered:
@cmd-ntrf I try your first suggestion but I'm not sure that it's enough. Almost everything can be convert to yaml with yamlencode (string, random text file, json object). However, it will catch resources pass to the variable and empty string.
For example, this is valid:
> yamlencode(file("bad.yaml"))
<<EOT
|
this is not a yaml file
a=>2
$i : 42
EOT
Forget my last comment, I realized that it was yamldecode instead of yamlencode. With yamldecode, it catches issues with invalid files. It's actually a good solution. I will send the PR.
If the yaml input provided in
var.hieradata
is invalid, Puppet will be unable to execute properly. We can prevent injecting invalid yaml by trying to first decode it usingyamldecode
in the validation block ofvar.hieradata
.The text was updated successfully, but these errors were encountered: