Skip to content

Commit

Permalink
feature: custom metlife stuff
Browse files Browse the repository at this point in the history
- templatized client.rb.erb
- removed ec2 hints from bootstrap script
- configurable http/https proxy for Chef
- no longer pulling down gpg key for chef opscode apt repo. doesn't
  seem to be needed and breaks the bootstrap

Change-Id: I492cb039f7d82df099748607d30308aa9e4e803c
  • Loading branch information
joshbronson committed Aug 6, 2014
1 parent 38082ab commit 6f0a7f6
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 9 deletions.
76 changes: 76 additions & 0 deletions config/client.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require "ohai"
require "json"

#
# Load configuration
#

def merge_safely hsh
hsh.merge!( yield ) rescue Mash.new
end

def create_file_if_empty(filename, str)
unless File.exists?(filename)
puts "Populating #{filename}" ;
File.open(filename, "w", 0600){|f| f.puts(str) }
end
end

def present?(config, key)
not config[key].to_s.empty?
end

# Start with a set of defaults
chef_config = Mash.new

merge_safely(chef_config) do
{
'chef_server' => '<%= @chef_config[:chef_server_url] %>',
'organization' => '<%= @chef_config[:organization] %>',
'client_key' => "<%= @client_key %>",
'node_name' => '<%= @server.full_name %>',
'realm_name' => '<%= @server.realm_name %>',
'cluster_name' => '<%= @server.cluster_name %>',
'facet_name' => '<%= @server.facet_name %>',
'facet_index' => '<%= @server.name %>',
}
end

#
# Configure chef run
#

log_level :info
log_location STDOUT
node_name chef_config["node_name"] if chef_config["node_name"]
chef_server_url chef_config["chef_server"] if chef_config["chef_server"]
validation_client_name chef_config["validation_client_name"] if chef_config["validation_client_name"]
validation_key "/etc/chef/validation.pem"
client_key "/etc/chef/client.pem"
node_attrs_file "/etc/chef/first-boot.json"

<%- if @server.selected_cloud.chef_http_proxy %>
http_proxy '<%= @server.selected_cloud.chef_http_proxy %>'
<%- end %>

<%- if @server.selected_cloud.chef_http_proxy %>
https_proxy '<%= @server.selected_cloud.chef_https_proxy %>'
<%- end %>


# If the client file is missing, write the validation key out so chef-client can register
unless File.exists?(client_key)
if present?(chef_config, "client_key") then create_file_if_empty(client_key, chef_config["client_key"])
elsif present?(chef_config, "validation_key") then create_file_if_empty(validation_key, chef_config["validation_key"])
else warn "Yikes -- I have no client key or validation key!!"
end
end

reduced_chef_config = chef_config.reject{|k,v| k.to_s =~ /(_key|run_list)$/ }
unless File.exists?(node_attrs_file)
create_file_if_empty(node_attrs_file, JSON.pretty_generate(reduced_chef_config))
end
json_attribs node_attrs_file

Chef::Log.debug(JSON.generate(chef_config))
Chef::Log.info("=> chef client #{node_name} on #{chef_server_url} in cluster +#{chef_config["cluster_name"]}+")
14 changes: 6 additions & 8 deletions lib/chef/knife/bootstrap/ubuntu12.04-ironfan.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ set -e
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | sudo tee /etc/apt/sources.list.d/opscode.list

# Make sure that opscode chef is on the apt repo list.
sudo mkdir -p /etc/apt/trusted.gpg.d
gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
gpg --export [email protected] | sudo tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null

# This key no longer seems to exist? Removing it doesn't seem to hurt
# anything. -- Josh
# sudo mkdir -p /etc/apt/trusted.gpg.d
# gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
# gpg --export [email protected] | sudo tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null

date > /etc/box_build_time

Expand Down Expand Up @@ -102,11 +105,6 @@ cat <<'EOP'
EOP
) > /etc/chef/first-boot.json

# Ensure that EC2 images are recognized even inside VPC
mkdir -p /etc/chef/ohai/hints/
touch /etc/chef/ohai/hints/ec2.json


echo -e "`date` \n\n**** \n**** Adding chef client nonce script:\n****\n"

cat > /etc/init.d/chef-client-nonce <<'EOP'
Expand Down
8 changes: 8 additions & 0 deletions lib/chef/knife/cluster_show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def _run

def dump_computer(computer)
header = "Computer #{computer.name} (#{computer.class})"

#puts "--------------------------------------------------------------------------------"
#puts "client script"
#puts "--------------------------------------------------------------------------------"
#puts computer.chef_client_script_content
#puts "--------------------------------------------------------------------------------"
#puts ""

with_verbosity 1 do
Chef::Log.info(header)

Expand Down
6 changes: 5 additions & 1 deletion lib/ironfan/broker/computer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ def chef_client_script_content
return @chef_client_script_content if @chef_client_script_content
return unless cloud.chef_client_script
script_filename = File.expand_path("../../../config/#{cloud.chef_client_script}", File.dirname(File.realdirpath(__FILE__)))
@chef_client_script_content = Ironfan.safely{ File.read(script_filename) }
@chef_config = Chef::Config
@client_key = File.read(Chef::Config[:client_key]).gsub("\n", "\\n")
@chef_client_script_content = Ironfan.safely do
Erubis::Eruby.new(File.read(script_filename)).evaluate(self)
end
end

#
Expand Down
2 changes: 2 additions & 0 deletions lib/ironfan/dsl/cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class Dsl

class Cloud < Ironfan::Dsl
magic :default_cloud, :boolean, :default => false
magic :chef_http_proxy, String
magic :chef_https_proxy, String

# Factory out to subclasses
def self.receive(obj, &block)
Expand Down

3 comments on commit 6f0a7f6

@westbywest
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to drop in uninvited with comments out of nowhere. I found you could pull GPG key for chef repo from opscode directly. Not installing the key doesn't interfere with bootstrap, at any rate, just foregoes verification of chef packages installed thereafter.
#357

@joshbronson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! updated. apologies for not having time at the moment to look at your PR for master branch.

@westbywest
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Just happened by chance to notice duplicate work underway.

Please sign in to comment.