Conditional SwitchTower Configuration
The SwitchTower configuration language does not, by itself, support multiple configurations in the same recipe file. That is to say, SwitchTower does not provide a way to say “in this circumstance, this machine is an app server, and in this other circumstance, this other machine is an app server.”
However, because the recipe files are simply Ruby scripts, you can take advantage of Ruby’s control structures to differentiate between multiple configurations based on (for instance) an environment variable:
1 2 3 4 5 6 7 |
if ENV["STAGE"] == "production" set :deploy_to, "/var/www/prod" role :app, "prod.example.com" else set :deploy_to, "/var/www/dev" role :app, "dev.example.com" end |
Then, you could just do:
1 |
STAGE=production switchtower -r config/deploy -a deploy |
Coming soon, SwitchTower will support setting variables directly from the command line, so you could set the variable via some -s
switch, and then query the variable in the recipe file.