diff options
-rw-r--r-- | lib/chef/knife/bootstrap/client_builder.rb | 12 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap/client_builder_spec.rb | 11 |
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb index 59b0cabd49..7eb1e22628 100644 --- a/lib/chef/knife/bootstrap/client_builder.rb +++ b/lib/chef/knife/bootstrap/client_builder.rb @@ -91,6 +91,16 @@ class Chef knife_config[:run_list] end + # @return [String] policy_name from the knife_config + def policy_name + knife_config[:policy_name] + end + + # @return [String] policy_group from the knife_config + def policy_group + knife_config[:policy_group] + end + # @return [Hash,Array] Object representation of json first-boot attributes from the knife_config def first_boot_attributes knife_config[:first_boot_attributes] @@ -141,6 +151,8 @@ class Chef node.run_list(normalized_run_list) node.normal_attrs = first_boot_attributes if first_boot_attributes node.environment(environment) if environment + node.policy_name = policy_name if policy_name + node.policy_group = policy_group if policy_group (knife_config[:tags] || []).each do |tag| node.tags << tag end diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb index 930ae8c9d3..e7232fe8d6 100644 --- a/spec/unit/knife/bootstrap/client_builder_spec.rb +++ b/spec/unit/knife/bootstrap/client_builder_spec.rb @@ -190,5 +190,16 @@ describe Chef::Knife::Bootstrap::ClientBuilder do expect(node).to receive(:run_list).with([]) client_builder.run end + + it "builds a node with policy_name and policy_group when given" do + knife_config[:policy_name] = "my-app" + knife_config[:policy_group] = "staging" + + expect(node).to receive(:run_list).with([]) + expect(node).to receive(:policy_name=).with("my-app") + expect(node).to receive(:policy_group=).with("staging") + + client_builder.run + end end end |