Ansible combines YAML with jinja2 to do this type of stuff, for instance.
I'm not totally certain, but I think that might end up being simpler, more expressive and more powerful than this.