Module: Awsborn::Chef::Rake

Defined in:
lib/awsborn/rake.rb

Overview

Just add a ‘Rakefile` in the same directory as your server definition file.

require 'awsborn'
include Awsborn::Chef::Rake
require './servers'

You are now able to run ‘rake` to start all servers and run Chef on each of them. Other rake tasks include:

  • ‘rake chef` - Run chef on all servers, or the ones specified with `host=name1,name2`.

  • ‘rake chef:debug` - Ditto, but with chef’s log level set to ‘debug`.

  • ‘rake start` - Start all servers (or host=name1,name2) but don’t run ‘chef`.

You can use ‘server=name1,name2` as a synonym for `host=…`

Instance Method Summary collapse

Instance Method Details

#cluster(args) ⇒ Object

:nodoc:



168
169
170
171
# File 'lib/awsborn/rake.rb', line 168

def cluster (args) #:nodoc:
  name = args[:c] || args[:cluster] || 'cluster 1'
  Awsborn::ServerCluster.clusters.detect { |c| c.name == name } || raise("Could not find cluster named '#{name}'")
end

#create_cookbook(dir) ⇒ Object

:nodoc:



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/awsborn/rake.rb', line 138

def create_cookbook(dir) #:nodoc:
  raise "Must provide a cookbook=" unless ENV["cookbook"]
  puts "** Creating cookbook #{ENV["cookbook"]}"
  sh "mkdir -p #{File.join(dir, ENV["cookbook"], "attributes")}" 
  sh "mkdir -p #{File.join(dir, ENV["cookbook"], "recipes")}" 
  sh "mkdir -p #{File.join(dir, ENV["cookbook"], "definitions")}" 
  sh "mkdir -p #{File.join(dir, ENV["cookbook"], "libraries")}" 
  sh "mkdir -p #{File.join(dir, ENV["cookbook"], "files", "default")}" 
  sh "mkdir -p #{File.join(dir, ENV["cookbook"], "templates", "default")}" 

  unless File.exists?(File.join(dir, ENV["cookbook"], "recipes", "default.rb"))
    open(File.join(dir, ENV["cookbook"], "recipes", "default.rb"), "w") do |file|
      file.puts <<-EOH
#
# Cookbook Name:: #{ENV["cookbook"]}
# Recipe:: default
#
EOH
    end
  end
end

#framed(message) ⇒ Object

:nodoc:



164
165
166
# File 'lib/awsborn/rake.rb', line 164

def framed (message) #:nodoc:
  '*' * (4 + message.length) + "\n* #{message} *\n" + '*' * (4 + message.length)
end

#get_hosts(args) ⇒ Object

:nodoc:



160
161
162
# File 'lib/awsborn/rake.rb', line 160

def get_hosts (args) #:nodoc:
  args[:host] && args[:host].split(',') || args[:server] && args[:server].split(',')
end


35
36
37
38
39
40
41
42
# File 'lib/awsborn/rake.rb', line 35

def print_required_dns_setting (info)
  puts "Make sure those NS records are present in your DNS settings:"
  puts(info.map do |dns_entry|
    dns_entry[:name_servers].map do |ns|
      "#{dns_entry[:name]}\tIN\tNS\t#{ns}."
    end
  end.join("\n"))
end