lib/chef/fork/commands/bootstrap.rb in chef-fork-0.1.2 vs lib/chef/fork/commands/bootstrap.rb in chef-fork-0.1.3
- old
+ new
@@ -11,11 +11,11 @@
class Chef
class Fork
module Commands
class Bootstrap < Ssh
def run(args=[])
- rest = optparse.parse(args)
+ rest = parse_args(args)
if hostname = rest.shift
command = bootstrap_command()
ssh(hostname, [command])
end
end
@@ -73,17 +73,27 @@
def bootstrap_command()
template_file = options[:template_file] || find_template(options[:distro])
if template_file
template = File.read(template_file)
- render_template(template)
+ command = render_template(template)
+ if options[:use_sudo]
+ "sudo #{command}"
+ else
+ command
+ end
else
- raise(NameError.new("Unknown distro: #{distro.inspect}"))
+ raise(NameError.new("Unknown distro: #{options[:distro].inspect}"))
end
end
def find_template(name)
- templates = $LOAD_PATH.map { |path| File.join(path, "chef", "knife", "bootstrap", "templates", "#{name}.erb") }
+ templates = $LOAD_PATH.map { |path|
+ [
+ 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)