Skip to content

Commit 6f0a7f6

Browse files
committed
feature: custom metlife stuff
- 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
1 parent 38082ab commit 6f0a7f6

File tree

5 files changed

+97
-9
lines changed

5 files changed

+97
-9
lines changed

config/client.rb.erb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require "ohai"
2+
require "json"
3+
4+
#
5+
# Load configuration
6+
#
7+
8+
def merge_safely hsh
9+
hsh.merge!( yield ) rescue Mash.new
10+
end
11+
12+
def create_file_if_empty(filename, str)
13+
unless File.exists?(filename)
14+
puts "Populating #{filename}" ;
15+
File.open(filename, "w", 0600){|f| f.puts(str) }
16+
end
17+
end
18+
19+
def present?(config, key)
20+
not config[key].to_s.empty?
21+
end
22+
23+
# Start with a set of defaults
24+
chef_config = Mash.new
25+
26+
merge_safely(chef_config) do
27+
{
28+
'chef_server' => '<%= @chef_config[:chef_server_url] %>',
29+
'organization' => '<%= @chef_config[:organization] %>',
30+
'client_key' => "<%= @client_key %>",
31+
'node_name' => '<%= @server.full_name %>',
32+
'realm_name' => '<%= @server.realm_name %>',
33+
'cluster_name' => '<%= @server.cluster_name %>',
34+
'facet_name' => '<%= @server.facet_name %>',
35+
'facet_index' => '<%= @server.name %>',
36+
}
37+
end
38+
39+
#
40+
# Configure chef run
41+
#
42+
43+
log_level :info
44+
log_location STDOUT
45+
node_name chef_config["node_name"] if chef_config["node_name"]
46+
chef_server_url chef_config["chef_server"] if chef_config["chef_server"]
47+
validation_client_name chef_config["validation_client_name"] if chef_config["validation_client_name"]
48+
validation_key "/etc/chef/validation.pem"
49+
client_key "/etc/chef/client.pem"
50+
node_attrs_file "/etc/chef/first-boot.json"
51+
52+
<%- if @server.selected_cloud.chef_http_proxy %>
53+
http_proxy '<%= @server.selected_cloud.chef_http_proxy %>'
54+
<%- end %>
55+
56+
<%- if @server.selected_cloud.chef_http_proxy %>
57+
https_proxy '<%= @server.selected_cloud.chef_https_proxy %>'
58+
<%- end %>
59+
60+
61+
# If the client file is missing, write the validation key out so chef-client can register
62+
unless File.exists?(client_key)
63+
if present?(chef_config, "client_key") then create_file_if_empty(client_key, chef_config["client_key"])
64+
elsif present?(chef_config, "validation_key") then create_file_if_empty(validation_key, chef_config["validation_key"])
65+
else warn "Yikes -- I have no client key or validation key!!"
66+
end
67+
end
68+
69+
reduced_chef_config = chef_config.reject{|k,v| k.to_s =~ /(_key|run_list)$/ }
70+
unless File.exists?(node_attrs_file)
71+
create_file_if_empty(node_attrs_file, JSON.pretty_generate(reduced_chef_config))
72+
end
73+
json_attribs node_attrs_file
74+
75+
Chef::Log.debug(JSON.generate(chef_config))
76+
Chef::Log.info("=> chef client #{node_name} on #{chef_server_url} in cluster +#{chef_config["cluster_name"]}+")

lib/chef/knife/bootstrap/ubuntu12.04-ironfan.erb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ set -e
1717
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | sudo tee /etc/apt/sources.list.d/opscode.list
1818

1919
# Make sure that opscode chef is on the apt repo list.
20-
sudo mkdir -p /etc/apt/trusted.gpg.d
21-
gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
22-
gpg --export [email protected] | sudo tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null
20+
21+
# This key no longer seems to exist? Removing it doesn't seem to hurt
22+
# anything. -- Josh
23+
# sudo mkdir -p /etc/apt/trusted.gpg.d
24+
# gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
25+
# gpg --export [email protected] | sudo tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null
2326

2427
date > /etc/box_build_time
2528

@@ -102,11 +105,6 @@ cat <<'EOP'
102105
EOP
103106
) > /etc/chef/first-boot.json
104107

105-
# Ensure that EC2 images are recognized even inside VPC
106-
mkdir -p /etc/chef/ohai/hints/
107-
touch /etc/chef/ohai/hints/ec2.json
108-
109-
110108
echo -e "`date` \n\n**** \n**** Adding chef client nonce script:\n****\n"
111109

112110
cat > /etc/init.d/chef-client-nonce <<'EOP'

lib/chef/knife/cluster_show.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ def _run
5959

6060
def dump_computer(computer)
6161
header = "Computer #{computer.name} (#{computer.class})"
62+
63+
#puts "--------------------------------------------------------------------------------"
64+
#puts "client script"
65+
#puts "--------------------------------------------------------------------------------"
66+
#puts computer.chef_client_script_content
67+
#puts "--------------------------------------------------------------------------------"
68+
#puts ""
69+
6270
with_verbosity 1 do
6371
Chef::Log.info(header)
6472

lib/ironfan/broker/computer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ def chef_client_script_content
146146
return @chef_client_script_content if @chef_client_script_content
147147
return unless cloud.chef_client_script
148148
script_filename = File.expand_path("../../../config/#{cloud.chef_client_script}", File.dirname(File.realdirpath(__FILE__)))
149-
@chef_client_script_content = Ironfan.safely{ File.read(script_filename) }
149+
@chef_config = Chef::Config
150+
@client_key = File.read(Chef::Config[:client_key]).gsub("\n", "\\n")
151+
@chef_client_script_content = Ironfan.safely do
152+
Erubis::Eruby.new(File.read(script_filename)).evaluate(self)
153+
end
150154
end
151155

152156
#

lib/ironfan/dsl/cloud.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ class Dsl
33

44
class Cloud < Ironfan::Dsl
55
magic :default_cloud, :boolean, :default => false
6+
magic :chef_http_proxy, String
7+
magic :chef_https_proxy, String
68

79
# Factory out to subclasses
810
def self.receive(obj, &block)

0 commit comments

Comments
 (0)