Skip to content

Commit dae731a

Browse files
author
Nuo Yan
committed
more fixes and improvements for environments
1 parent 1e74eaf commit dae731a

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎chef/lib/chef/knife/bootstrap.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Bootstrap < Knife
4747
:short => "-N NAME",
4848
:long => "--node-name NAME",
4949
:description => "The Chef node name for your new node"
50-
50+
5151
option :prerelease,
5252
:long => "--prerelease",
5353
:description => "Install the pre-release chef gems"

‎chef/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ validation_client_name "<%= Chef::Config[:validation_client_name] %>"
3030
# Using default node name"
3131
<% else %>
3232
node_name "<%= @config[:chef_node_name] %>"
33-
<% end %>
33+
<% end %>
34+
<% if Chef::Config[:environment] != nil %>
35+
environment "<%= Chef::Config[:environment]%>"
36+
<% end %>
3437
EOP
3538
) > /etc/chef/client.rb
3639

‎chef/lib/chef/knife/ec2_server_create.rb‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def run
170170

171171
puts("\n")
172172

173-
174173
puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
175174
puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
176175
puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
@@ -180,7 +179,6 @@ def run
180179

181180
print(".") until tcp_test_ssh(server.dns_name) { sleep @initial_sleep_delay ||= 10; puts("done") }
182181

183-
184182
bootstrap_for_node(server).run
185183

186184
puts "\n"
@@ -208,6 +206,7 @@ def bootstrap_for_node(server)
208206
bootstrap.config[:distro] = config[:distro]
209207
bootstrap.config[:use_sudo] = true
210208
bootstrap.config[:template_file] = config[:template_file]
209+
bootstrap.config[:environment] = config[:environment]
211210
bootstrap
212211
end
213212

‎chef/lib/chef/node.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ def self.find_or_create(node_name)
565565
def self.build(node_name)
566566
node = new
567567
node.name(node_name)
568+
node.chef_environment(Chef::Config[:environment]) unless Chef::Config[:environment].nil? || Chef::Config[:environment].chop.empty?
568569
node
569570
end
570571

‎chef/lib/chef/role.rb‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@ def run_list_for_environment(environment='_default')
122122
end
123123
end
124124

125-
def env_run_lists(hash=nil)
125+
def env_run_lists(hash=nil, run_list_items_only=false)
126126
# TODO: should have btter validation, but leaving it as it is for now to make everything work first [nuo]
127127
if (!hash.nil? && hash.length > 0)
128128
hash.each do |k,v|
129-
unless v["run_list"].nil? || v["run_list"].empty?
130-
v["run_list"] = Chef::RunList.new(k).reset!(v["run_list"])
129+
unless v["run_list"].nil?
130+
rl = Chef::RunList.new(k).reset!(v["run_list"])
131+
v["run_list"] = run_list_items_only ? rl.run_list_items : rl
131132
end
132133
end
133134
@env_run_lists = hash
@@ -166,7 +167,7 @@ def to_hash
166167
"override_attributes" => @override_attributes,
167168
"chef_type" => "role",
168169
"run_list" => @run_list.run_list,
169-
"env_run_lists" => @env_run_lists
170+
"env_run_lists" => env_run_lists(@env_run_lists, true)
170171
}
171172
result["_rev"] = couchdb_rev if couchdb_rev
172173
result

0 commit comments

Comments
 (0)