Fixed various issues with variable substitution in template files:
make variables available during deploy, undeploy, install, upgrade etc
fixed use of ${randomhex(12)} and the like