As far as I know, template creation has already been sufficiently automated. Here is a take on how to achieve it with salt:
(Btw, you can find some further reading on using salt with QubesOS in the official documentation.)
But as for me, template management is not something I do a lot of, so I find it perfectly sufficient to keep a record of my installed packages in a text file.
If you don’t know what you’ve installed since the template was created, check the logs:
sudo zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep ^Commandline: