Sometimes an application will start out with a need for just a configuration
format, but over time you end up with many many similar stanzas, and you
would like to share parts between them, and abstract some repetition away.
This tends to happen in for example Kubernetes and GitHub Actions. When the
configuration language does not support abstraction, people often reach for
templating, which is a bad idea for the reasons explained earlier.
Proper programming languages, possibly domain-specific ones, are a better
fit. Some of my favorites are Nix and Python
Templating is fine with YAML if you don't do it with strings but with a system that turns one YAML document into another YAML document, that is, do your substitutions in the YAML universe.
The "code up your configuration in your favorite programming language" can really work but it frequently becomes a point of frustration itself. As much as I want to like YAML it has a number of intrinsic problems like the Norway problem... But I do think people are confusing the accidental and essential complexity and because of that they flinch and reach for non-solutions to the problems of configuration rather than really thinking it through.
The "code up your configuration in your favorite programming language" can really work but it frequently becomes a point of frustration itself. As much as I want to like YAML it has a number of intrinsic problems like the Norway problem... But I do think people are confusing the accidental and essential complexity and because of that they flinch and reach for non-solutions to the problems of configuration rather than really thinking it through.