Write it in a higher level language and generate the YAML from that. See the YAML as a wire protocol, not something you author things in.
however, you don't want config being turing complete, that creates a host of other problems at a layer you don't want them
If your config is turing complete and consumed as-is, then without a lot of discipline you can dig yourself into a hole, sure.
If you're producing YAML that is not turing complete, that constraint means you have to code in a way that produces deterministic output. It's actually very safe, and YAML maps 1:1 to types in something like Python.
My favourite go-to example is for AWS Cloudformation: