Returns the current server
# File lib/do/commands.rb, line 22 def current_server @_current_server end
# File lib/do/commands.rb, line 55 def load_recipe(path) instance_eval(File.read(path), __FILE__, __LINE__) end
# File lib/do/commands.rb, line 51 def load_recipes recipes.each { |f| load_recipe(f) } end
Log text under current_server if available
# File lib/do/commands.rb, line 112 def log(text="", new_line=true) current_server ? current_server.log(text, new_line) : super(text, new_line) end
# File lib/do/commands.rb, line 123 def method_missing(method, *args, &block) current_server && current_server.respond_to?(method) ? current_server.send(method, *args) : super(method, *args, &block) end
Install in your DO_PATH a remote task
# You can install/update task with # rake plugin:configuration plugin "configuration", "https://gist.github.com/raw/xys.rake"
# File lib/do/commands.rb, line 96 def plugin(name, repo) desc "install #{name} plugin" namespace :plugin do task(name => 'setup') do log "\e[36m## Installing plugin %s\e[0m" % name Dir.mkdir(DO_PATH) unless File.exist?(DO_PATH) path = File.join(DO_PATH, '%s.rake' % name) sh :curl, '--location', '--progress-bar', repo, '>', path load_recipe(path) end end end
DO loads rakefiles in these locations:
~/do/dorc ~/do/*.rake ./Do ./Dofile
DO_PATH, default is ~/do.
# File lib/do/commands.rb, line 43 def recipes @_recipes ||= ( ]dorc **/*.rake].map { |f| Dir[File.join(DO_PATH, f)] }.flatten + ]./Do ./Dofile].map { |f| File.expand_path(f) } << File.expand_path('../common.rb', __FILE__) ).reject { |f| !File.exist?(f) } end
# File lib/do/commands.rb, line 15 def remote servers.map(&:name) end
Run commands on current_server if available
# File lib/do/commands.rb, line 119 def run(*args) current_server ? current_server.run(*args) : super(*args) end
This method define our servers
keys = %w[key1.pem key2.pem key3.pem key4.pem] server :srv1, 's1.domain.local', 'user', :keys => keys server :srv2, 's2.domain.local', 'user', :keys => keys server :srv3, 's3.domain.local', 'user', :keys => keys server :srv4, 's4.domain.local', 'user', :keys => keys
# File lib/do/commands.rb, line 70 def server(name, host, user, options={}) servers.push(DO::Server.new(name, host, user, options)) task name do |opts, b| allowed = opts.map { |k,v| k if remote.include?(k) && v }.compact denied = opts.map { |k,v| k if remote.include?(k) && v == false }.compact if (allowed.empty? && denied.empty?) || (!allowed.empty? && allowed.include?(name)) || (!denied.empty? && !denied.include?(name)) @_current_server = servers.find { |s| s.name == name } begin b.arity == 1 ? b.call(opts) : b.call ensure @_current_server = nil end end end end
Array of DO::Server defined in our tasks
# File lib/do/commands.rb, line 11 def servers @_servers ||= [] end
Generated with the Darkfish Rdoc Generator 2.