lib/chef/fork/commands/bootstrap.rb in chef-fork-0.1.4 vs lib/chef/fork/commands/bootstrap.rb in chef-fork-0.2.0
- old
+ new
@@ -1,14 +1,15 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require "chef"
require "chef/config"
-require "chef/knife/core/bootstrap_context"
+require "chef/encrypted_data_bag_item"
require "erubis"
require "json"
require "shellwords"
+require "chef/fork/bootstrap/context"
require "chef/fork/commands/ssh"
class Chef
class Fork
module Commands
@@ -92,18 +93,36 @@
end
def find_template(name)
templates = $LOAD_PATH.map { |path|
[
+ File.join(path, "chef", "fork", "bootstrap", "templates", "#{name}.erb"), # Chef 12.x
+ File.join(path, "chef", "fork", "bootstrap", "#{name}.erb"), # Chef 11.x
File.join(path, "chef", "knife", "bootstrap", "templates", "#{name}.erb"), # Chef 12.x
File.join(path, "chef", "knife", "bootstrap", "#{name}.erb"), # Chef 11.x
]
}.reduce(:+)
templates.find { |path| File.exist?(path) }
end
def render_template(template)
- context = Chef::Knife::Core::BootstrapContext.new(options, options[:run_list], Chef::Config)
+ case Chef::VERSION.split(".").first
+ when "11"
+ context = Chef::Fork::Bootstrap::Context.new(options, options[:run_list], Chef::Config)
+ else
+ if Chef::Config[:knife][:secret]
+ secret = Chef::Config[:knife][:secret]
+ else
+ if Chef::Config[:knife][:secret_file]
+ secret = Chef::EncryptedDataBagItem.load_secret(Chef::Config[:knife][:secret_file])
+ end
+ end
+ if secret
+ context = Chef::Fork::Bootstrap::Context.new(options, options[:run_list], Chef::Config, secret)
+ else
+ context = Chef::Fork::Bootstrap::Context.new(options, options[:run_list], Chef::Config)
+ end
+ end
Erubis::Eruby.new(template).evaluate(context)
end
end
end
end