diff options
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 6 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/client_builder.rb | 3 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap/client_builder_spec.rb | 16 |
3 files changed, 25 insertions, 0 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index a4095e8402..157c815a98 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -143,6 +143,12 @@ class Chef :proc => lambda { |o| o.split(/[\s,]+/) }, :default => [] + option :tags, + :long => "--tags TAGS", + :description => "Comma separated list of tags to apply to the node", + :proc => lambda { |o| o.split(/[\s,]+/) }, + :default => [] + option :first_boot_attributes, :short => "-j JSON_ATTRIBS", :long => "--json-attributes", diff --git a/lib/chef/knife/bootstrap/client_builder.rb b/lib/chef/knife/bootstrap/client_builder.rb index b9c1d98bec..32258f6fa5 100644 --- a/lib/chef/knife/bootstrap/client_builder.rb +++ b/lib/chef/knife/bootstrap/client_builder.rb @@ -140,6 +140,9 @@ class Chef node.run_list(normalized_run_list) node.normal_attrs = first_boot_attributes if first_boot_attributes node.environment(environment) if environment + (knife_config[:tags] || []).each do |tag| + node.tags << tag + end node end end diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb index e6aa307c7e..930ae8c9d3 100644 --- a/spec/unit/knife/bootstrap/client_builder_spec.rb +++ b/spec/unit/knife/bootstrap/client_builder_spec.rb @@ -149,6 +149,22 @@ describe Chef::Knife::Bootstrap::ClientBuilder do client_builder.run end + it "does not add tags by default" do + allow(node).to receive(:run_list).with([]) + expect(node).to_not receive(:tags) + client_builder.run + end + + it "adds tags to the node when given" do + tag_receiver = [] + + knife_config[:tags] = %w[foo bar] + allow(node).to receive(:run_list).with([]) + allow(node).to receive(:tags).and_return(tag_receiver) + client_builder.run + expect(tag_receiver).to eq %w[foo bar] + end + it "builds a node when the run_list is a string" do knife_config[:run_list] = "role[base],role[app]" expect(node).to receive(:run_list).with(["role[base]", "role[app]"]) |