summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsawanoboly <sawanoboriyu@higanworks.com>2015-09-09 17:56:08 +0900
committerLamont Granquist <lamont@scriptkiddie.org>2015-10-24 20:25:10 -0700
commit4731e4bbe5a240ea9b1a725be6c41246ef4fe4a5 (patch)
tree40cad948f7486bbdbd1a71f7c576208ca3d244d6
parent3bdfa8f65cf19563e35d2bad3f7fcf9263ac7881 (diff)
downloadchef-4731e4bbe5a240ea9b1a725be6c41246ef4fe4a5.tar.gz
add option first_boot_attributes_from_file
-rw-r--r--lib/chef/exceptions.rb1
-rw-r--r--lib/chef/knife/bootstrap.rb18
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index 6e7ff2e24a..2d60faa0c9 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -74,6 +74,7 @@ class Chef
class InvalidPrivateKey < ArgumentError; end
class MissingKeyAttribute < ArgumentError; end
class KeyCommandInputError < ArgumentError; end
+ class BootstrapCommandInputError < ArgumentError; end
class InvalidKeyArgument < ArgumentError; end
class InvalidKeyAttribute < ArgumentError; end
class InvalidUserAttribute < ArgumentError; end
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 387f1c90fa..ea623b4f3e 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -171,6 +171,12 @@ class Chef
:proc => lambda { |o| Chef::JSONCompat.parse(o) },
:default => {}
+ option :first_boot_attributes_from_file,
+ :long => "--json-attribute-file FILE",
+ :description => "A JSON file to be used to the first run of chef-client",
+ :proc => lambda { |o| Chef::JSONCompat.parse(File.read(o)) },
+ :default => nil
+
option :host_key_verify,
:long => "--[no-]host-key-verify",
:description => "Verify host key, enabled by default.",
@@ -253,6 +259,13 @@ class Chef
)
end
+ def jsonstring_and_jsonfile_msg
+<<EOS
+You cannot pass both --json-attributes and --json-attribute-file.
+Please pass one or none.
+EOS
+ end
+
# The default bootstrap template to use to bootstrap a server This is a public API hook
# which knife plugins use or inherit and override.
#
@@ -341,6 +354,11 @@ class Chef
end
def run
+ if @config[:first_boot_attributes].any? && @config[:first_boot_attributes_from_file]
+ raise Chef::Exceptions::BootstrapCommandInputError, jsonstring_and_jsonfile_msg
+ end
+ @config[:first_boot_attributes].merge!(@config[:first_boot_attributes_from_file]) if @config[:first_boot_attributes_from_file]
+
validate_name_args!
validate_options!