Something similar but superior (IMHO) has already been implemented for WordPress by the roots guys as part of their Bedrock project. Their approach is much simpler and uses environment variables stored in .env files. When combined with Capistrano deploys, it works like a charm.

http://roots.io/wordpress-stack/