This needs to be sync'ed with the small changes to this method that were done in barclamp-deployer.