Created
January 30, 2012 09:44
-
-
Save btisdall/1703593 to your computer and use it in GitHub Desktop.
Semi-automatic deploy using Puppet & Capistrano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load "servers" # this file contains our role definitions | |
def run_on_nodes(cmd) | |
# Use a default role | |
unless exists?(:servers) | |
set :servers, "dev" | |
end | |
# invoke find_servers() appropriately depending on whether the 'restrict' opt was passed. | |
# I'm sure there's a better way... | |
if exists?(:restrict) | |
servers_selected = find_servers :roles => "#{servers}", :only => { :"#{restrict}" => true } | |
else | |
servers_selected = find_servers :roles => "#{servers}" | |
end | |
if servers_selected.length == 0 | |
logger.info "No servers matched, quitting..." | |
exit | |
end | |
logger.info %Q{About to run "#{cmd}" on servers:} | |
servers_selected.each do |s| | |
logger.info "#{s}" | |
end | |
set(:reply) do | |
Capistrano::CLI.ui.ask " ** Proceed? (y/N): " | |
end | |
reply.downcase == "y" || exit | |
run "#{cmd}", :hosts => servers_selected | |
end | |
task pdeploy do | |
run_on_nodes("sudo puppetd --test --noop") | |
end | |
task get_uptime do | |
run_on_nodes("uptime") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment