This post originated from an RSS feed registered with Ruby Buzz
by Jamis Buck.
Original Post: Conditional SwitchTower Configuration
Feed Title: the buckblogs here
Feed URL: http://weblog.jamisbuck.org/blog.cgi/programming/index.rss
Feed Description: Jamis Buck's corner of the blogging universe. Mostly about ruby, but includes ramblings on a variety of topics.
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:
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:
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.