provisioners/chef: command builder for Linux
This commit is contained in:
parent
909cda4bd1
commit
7022b1c29d
|
@ -0,0 +1,15 @@
|
|||
module VagrantPlugins
|
||||
module Chef
|
||||
class CommandBuilder
|
||||
def initialize(machine, config, client_type)
|
||||
@machine = machine
|
||||
@config = config
|
||||
@client_type = client_type
|
||||
|
||||
if client_type != :solo && client_type != :client
|
||||
raise 'Invalid client_type, expected solo or client'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,47 @@
|
|||
module VagrantPlugins
|
||||
module Chef
|
||||
class CommandBuilderLinux < CommandBuilder
|
||||
def build_command
|
||||
if @client_type == :solo
|
||||
return build_command_solo
|
||||
else
|
||||
return build_command_client
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def build_command_client
|
||||
command_env = @config.binary_env ? "#{@config.binary_env} " : ""
|
||||
command_args = @config.arguments ? " #{@config.arguments}" : ""
|
||||
|
||||
binary_path = "chef-client"
|
||||
binary_path ||= File.join(@config.binary_path, binary_path)
|
||||
|
||||
return "#{command_env}#{binary_path} " +
|
||||
"-c #{@config.provisioning_path}/client.rb " +
|
||||
"-j #{@config.provisioning_path}/dna.json #{command_args}"
|
||||
end
|
||||
|
||||
def build_command_solo
|
||||
options = [
|
||||
"-c #{@config.provisioning_path}/solo.rb",
|
||||
"-j #{@config.provisioning_path}/dna.json"
|
||||
]
|
||||
|
||||
if !@machine.env.ui.is_a?(Vagrant::UI::Colored)
|
||||
options << "--no-color"
|
||||
end
|
||||
|
||||
command_env = @config.binary_env ? "#{@config.binary_env} " : ""
|
||||
command_args = @config.arguments ? " #{@config.arguments}" : ""
|
||||
|
||||
binary_path = "chef-solo"
|
||||
binary_path ||= File.join(@config.binary_path, binary_path)
|
||||
|
||||
return "#{command_env}#{binary_path} " +
|
||||
"#{options.join(" ")} #{command_args}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,14 @@
|
|||
require "pathname"
|
||||
|
||||
require "vagrant"
|
||||
|
||||
module VagrantPlugins
|
||||
module Chef
|
||||
root = Pathname.new(File.expand_path("../", __FILE__))
|
||||
autoload :CommandBuilder, root.join("command_builder")
|
||||
autoload :CommandBuilderLinux, root.join("command_builder_linux")
|
||||
autoload :CommandBuilderWindows, root.join("command_builder_windows")
|
||||
|
||||
class Plugin < Vagrant.plugin("2")
|
||||
name "chef"
|
||||
description <<-DESC
|
||||
|
|
|
@ -23,6 +23,15 @@ module VagrantPlugins
|
|||
:binary => binary)
|
||||
end
|
||||
|
||||
# This returns the command to run Chef for the given client
|
||||
# type.
|
||||
def build_command(client)
|
||||
builder_klass = CommandBuilderLinux
|
||||
builder_klass = CommandBuilderWindows if windows?
|
||||
builder = builder_klass.new(@machine, @config, client)
|
||||
return builder.build_command
|
||||
end
|
||||
|
||||
# Returns the path to the Chef binary, taking into account the
|
||||
# `binary_path` configuration option.
|
||||
def chef_binary_path(binary)
|
||||
|
|
|
@ -66,11 +66,7 @@ module VagrantPlugins
|
|||
error_check: false)
|
||||
end
|
||||
|
||||
command_env = @config.binary_env ? "#{@config.binary_env} " : ""
|
||||
command_args = @config.arguments ? " #{@config.arguments}" : ""
|
||||
command = "#{command_env}#{chef_binary_path("chef-client")} " +
|
||||
"-c #{@config.provisioning_path}/client.rb " +
|
||||
"-j #{@config.provisioning_path}/dna.json #{command_args}"
|
||||
command = build_command(:client)
|
||||
|
||||
@config.attempts.times do |attempt|
|
||||
if attempt == 0
|
||||
|
|
|
@ -142,19 +142,7 @@ module VagrantPlugins
|
|||
error_check: false)
|
||||
end
|
||||
|
||||
options = [
|
||||
"-c #{@config.provisioning_path}/solo.rb",
|
||||
"-j #{@config.provisioning_path}/dna.json"
|
||||
]
|
||||
|
||||
if !@machine.env.ui.is_a?(Vagrant::UI::Colored)
|
||||
options << "--no-color"
|
||||
end
|
||||
|
||||
command_env = @config.binary_env ? "#{@config.binary_env} " : ""
|
||||
command_args = @config.arguments ? " #{@config.arguments}" : ""
|
||||
command = "#{command_env}#{chef_binary_path("chef-solo")} " +
|
||||
"#{options.join(" ")} #{command_args}"
|
||||
command = build_command(:solo)
|
||||
|
||||
@config.attempts.times do |attempt|
|
||||
if attempt == 0
|
||||
|
|
Loading…
Reference in New Issue