lib/stack.rb in stack-kicker-0.0.22 vs lib/stack.rb in stack-kicker-0.0.23
- old
+ new
@@ -246,24 +246,10 @@
end
def Stack.generate_knife_rb(config)
# generate a project/.chef/knife.rb from our config
- Stack.check_config(config)
-
- # find the chef server, if we need to
- if config[:chef_server_hostname].nil? || config[:chef_server_private].nil? || config[:chef_server_public]
- Logger.debug { "Attempting to discover the chef server details" }
- ours = Stack.get_our_instances(config)
- ours.each do |node, node_details|
- if node_details[:role] == :chef
- Logger.debug { "Found the Chef server: #{node} #{node_details}" }
- Stack.set_chef_server(config, node)
- end
- end
- end
-
# CWD shoud be chef-repo/bootstrap, so the project .chef directory should be
dot_chef_abs = File.absolute_path(File.join(config[:stackhome],config[:dot_chef]))
if !File.directory?(dot_chef_abs)
Logger.warn "#{dot_chef_abs} doesn't exist, creating it..."
@@ -634,27 +620,33 @@
def Stack.set_chef_server(config, chef_server)
# set the private & public URLs for the chef server,
# called either after we create the Chef Server, or skip over it
Logger.debug "Setting :chef_server_hostname, chef_server_private & chef_server_public details (using #{chef_server})"
+ Stack.check_config(config)
+ Stack.get_our_instances(config)
+
config[:chef_server_hostname] = chef_server
+
# get the internal IP of this instance....which we should have stored in config[:all_instances]
if config[:all_instances][chef_server] && config[:all_instances][chef_server][:addresses]
config[:all_instances][chef_server][:addresses].each do |address|
# find the private IP, any old private IP will do...
if (address.label == 'private')
- config[:chef_server_private] = "http://#{address.address}:4000/"
+ config[:chef_server_private] = "#{address.address}"
Logger.info "Setting the internal Chef URL to #{config[:chef_server_private]}"
end
# only set the public url if it hasn't been set in the config
if ((config[:chef_server_public].nil? || config[:chef_server_public].empty?) && address.label == 'public')
- config[:chef_server_public] = "http://#{address.address}:4000/"
+ config[:chef_server_public] = "#{address.address}"
Logger.info "Setting the public Chef URL to #{config[:chef_server_public]}"
end
end
end
+
+
end
def Stack.secgroup_sync(config)
# 1) get all the IP information we have
# 2) generate the json to describe that to the "stackhelper secgroup-sync" tool
@@ -772,16 +764,17 @@
Logger.debug { "multipart = #{multipart}" }
# 2) replace the tokens (CHEF_SERVER, CHEF_ENVIRONMENT, SERVER_NAME, ROLE)
Logger.debug { "Replacing %HOSTNAME% with #{hostname} in multipart" }
multipart.gsub!(%q!%HOSTNAME%!, hostname)
+ Logger.debug { "Replaced %HOSTNAME% with #{hostname} in multipart" }
if config[:chef_server_hostname].nil?
Logger.info "config[:chef_server_hostname] is nil, skipping chef server substitution"
elsif (role_details[:chef_server])
Logger.info "This is the Chef Server - setting up to talk to ourselves"
- multipart.gsub!(%q!%CHEF_SERVER%!, 'http://127.0.0.1:4000/')
+ multipart.gsub!(%q!%CHEF_SERVER%!, '127.0.0.1')
multipart.gsub!(%q!%CHEF_ENVIRONMENT%!, config[:chef_environment])
else
Logger.info "Chef server is #{config[:chef_server_hostname]}, which is in #{config[:node_details][config[:chef_server_hostname]][:region]}"
Logger.info "#{hostname}'s region is #{config[:node_details][hostname][:region]}"
@@ -792,10 +785,16 @@
multipart.gsub!(%q!%CHEF_SERVER%!, config[:chef_server_public])
else
Logger.warn { "Not setting the chef url for #{hostname} as neither chef_server_private or chef_server_public are valid yet" }
end
+ if config[:domain].nil?
+ multipart.gsub!(%q!%CHEF_SERVER_HOSTNAME%!, config[:chef_server_hostname])
+ else
+ multipart.gsub!(%q!%CHEF_SERVER_HOSTNAME%!, config[:chef_server_hostname] + '.' + config[:domain])
+ end
+
multipart.gsub!(%q!%CHEF_ENVIRONMENT%!, config[:chef_environment])
if File.exists?(config[:chef_validation_pem])
multipart.gsub!(%q!%CHEF_VALIDATION_PEM%!, File.read(config[:chef_validation_pem]))
else
@@ -865,11 +864,11 @@
Stack.get_all_instances(config, true)
# refresh the chef_server details..we should have IPs now
if role_details[:chef_server]
Stack.set_chef_server(config, hostname)
- Stack.generate_knife_rb(config)
+ #Stack.generate_knife_rb(config)
end
# attach a floating IP to this if we have one
if role_details[:floating_ips] && role_details[:floating_ips][p-1]
floating_ip = role_details[:floating_ips][p-1]
@@ -913,18 +912,21 @@
if filename.nil? || filename.empty?
raise ArgumentError
end
+ filename_fqp = ''
+
+ # Relative path, to somewhere!
dirs = [ '.' ] # current directory
dirs.push(config[:stackhome])
config[:find_file_paths].each { |fp| dirs.push(File.join(config[:stackhome], fp)) }
dirs.push(File.join(@@gemhome, 'lib'))
+ dirs.push(ENV['HOME'])
dirs.push('') # find absolute paths
dirs.flatten!
Logger.debug "find_file, looking for #{filename} in #{dirs}"
- filename_fqp = ''
dirs.each do |dir|
fqp = File.join(dir, filename)
Logger.debug "find_file: checking #{fqp}"
if File.file?(fqp)
Logger.debug "find_file: found #{fqp}!"