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:



170
171
172
173
# File 'lib/awsborn/rake.rb', line 170

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

#cluster_param(args) ⇒ Object



179
180
181
# File 'lib/awsborn/rake.rb', line 179

def cluster_param(args)
  args[:c] || args[:cluster] || ENV['c'] || ENV['cluster']
end

#create_cookbook(dir) ⇒ Object

:nodoc:



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

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:



166
167
168
# File 'lib/awsborn/rake.rb', line 166

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

#get_hosts(args) ⇒ Object

:nodoc:



162
163
164
# File 'lib/awsborn/rake.rb', line 162

def get_hosts (args) #:nodoc:
  host_param(args) && host_param(args).split(',')
end

#host_param(args) ⇒ Object



175
176
177
# File 'lib/awsborn/rake.rb', line 175

def host_param(args)
  args[:host] || args[:server] || ENV['host'] || ENV['server']
end


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

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