Where there's a will there's a way. I kept getting stuck at different points trying to automate things. I kept persevering because I figure anything a human can tell a machine to do, it should be able to do it by itself somehow. I managed to jump over all the roadblocks and achieve a reliable way to recreate a mail server (which is a real pain) altogether with SSL certificates included.