Added a `--provision-with` flag to specify provisioners to use. [GH-367]
This commit is contained in:
parent
566a751d6f
commit
bb2a473549
|
@ -37,6 +37,8 @@
|
||||||
host will be created if it doesn't exist.
|
host will be created if it doesn't exist.
|
||||||
- Added `--force` flag to `box add`, which will overwite any existing boxes
|
- Added `--force` flag to `box add`, which will overwite any existing boxes
|
||||||
if they exist. [GH-631]
|
if they exist. [GH-631]
|
||||||
|
- Added `--provision-with` to `up` which configures what provisioners run,
|
||||||
|
by shortcut. [GH-367]
|
||||||
- Removed Thor as a dependency for the command line interfaces. This resulted
|
- Removed Thor as a dependency for the command line interfaces. This resulted
|
||||||
in general speed increases across all command line commands.
|
in general speed increases across all command line commands.
|
||||||
- Linux uses `shutdown -h` instead of `halt` to hopefully more consistently
|
- Linux uses `shutdown -h` instead of `halt` to hopefully more consistently
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
|
require "log4r"
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Action
|
module Action
|
||||||
module VM
|
module VM
|
||||||
class Provision
|
class Provision
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
|
@logger = Log4r::Logger.new("vagrant::action::vm::provision")
|
||||||
@app = app
|
@app = app
|
||||||
@env = env
|
@env["provision.enabled"] = true if !env.has_key?("provision.enabled")
|
||||||
@env["provision.enabled"] = true if !@env.has_key?("provision.enabled")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
@env = env
|
||||||
|
|
||||||
provisioners = nil
|
provisioners = nil
|
||||||
|
|
||||||
# We set this here so that even if this value is changed in the future,
|
# We set this here so that even if this value is changed in the future,
|
||||||
|
@ -34,9 +38,23 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled_provisioners
|
def enabled_provisioners
|
||||||
@env[:vm].config.vm.provisioners.map do |provisioner|
|
enabled = []
|
||||||
provisioner.provisioner.new(@env, provisioner.config)
|
@env[:vm].config.vm.provisioners.each do |provisioner|
|
||||||
end
|
if @env["provision.types"]
|
||||||
|
# If we've specified types of provisioners to enable, then we
|
||||||
|
# only use those provisioners, and skip any that we haven't
|
||||||
|
# specified.
|
||||||
|
if !@env["provision.types"].include?(provisioner.shortcut.to_s)
|
||||||
|
@logger.debug("Skipping provisioner: #{provisioner.shortcut}")
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
enabled << provisioner.provisioner.new(@env, provisioner.config)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return the enable provisioners
|
||||||
|
enabled
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,10 @@ module Vagrant
|
||||||
module Command
|
module Command
|
||||||
class Up < Base
|
class Up < Base
|
||||||
def execute
|
def execute
|
||||||
options = { :provision => true }
|
options = {
|
||||||
|
:provision => true,
|
||||||
|
:provisioners => nil
|
||||||
|
}
|
||||||
|
|
||||||
opts = OptionParser.new do |opts|
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: vagrant up [vm-name] [--[no-]provision] [-h]"
|
opts.banner = "Usage: vagrant up [vm-name] [--[no-]provision] [-h]"
|
||||||
|
@ -14,22 +17,33 @@ module Vagrant
|
||||||
opts.on("--[no-]provision", "Enable or disable provisioning") do |p|
|
opts.on("--[no-]provision", "Enable or disable provisioning") do |p|
|
||||||
options[:provision] = p
|
options[:provision] = p
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on("--provision-with x,y,z", Array,
|
||||||
|
"Enable only certain provisioners, by type.") do |list|
|
||||||
|
options[:provisioners] = list
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
argv = parse_options(opts)
|
argv = parse_options(opts)
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
|
# Parameters to send to actions
|
||||||
|
action_params = {
|
||||||
|
"provision.enabled" => options[:provision],
|
||||||
|
"provision.types" => options[:provisioners]
|
||||||
|
}
|
||||||
|
|
||||||
# Go over each VM and bring it up
|
# Go over each VM and bring it up
|
||||||
@logger.debug("'Up' each target VM...")
|
@logger.debug("'Up' each target VM...")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv[0]) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
@logger.info("Booting: #{vm.name}")
|
@logger.info("Booting: #{vm.name}")
|
||||||
vm.ui.info I18n.t("vagrant.commands.up.vm_created")
|
vm.ui.info I18n.t("vagrant.commands.up.vm_created")
|
||||||
vm.start("provision.enabled" => options[:provision])
|
vm.start(action_params)
|
||||||
else
|
else
|
||||||
@logger.info("Creating: #{vm.name}")
|
@logger.info("Creating: #{vm.name}")
|
||||||
vm.up("provision.enabled" => options[:provision])
|
vm.up(action_params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,7 +82,8 @@ module Vagrant
|
||||||
env[:vm].channel.upload(path.to_s, config.upload_path)
|
env[:vm].channel.upload(path.to_s, config.upload_path)
|
||||||
|
|
||||||
# Execute it with sudo
|
# Execute it with sudo
|
||||||
env[:vm].channel.sudo(command) do |ch, type, data|
|
env[:vm].channel.sudo(command) do |type, data|
|
||||||
|
if [:stderr, :stdout].include?(type)
|
||||||
# Output the data with the proper color based on the stream.
|
# Output the data with the proper color based on the stream.
|
||||||
color = type == :stdout ? :green : :red
|
color = type == :stdout ? :green : :red
|
||||||
|
|
||||||
|
@ -95,3 +96,4 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -24,4 +24,21 @@ vf
|
||||||
result_file = environment.workdir.join("results")
|
result_file = environment.workdir.join("results")
|
||||||
result_file.exist?.should_not be
|
result_file.exist?.should_not be
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "only uses the provisioners specified with `--provision-with`" do
|
||||||
|
# Skeleton for multiple provisioners
|
||||||
|
environment.skeleton!("provisioner_multi")
|
||||||
|
|
||||||
|
# Setup the basic environment
|
||||||
|
require_box("default")
|
||||||
|
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
||||||
|
|
||||||
|
# Bring up the VM, only using the shell provisioner
|
||||||
|
assert_execute("vagrant", "up", "--provision-with", "shell")
|
||||||
|
|
||||||
|
# Verify the file the shell provisioner made is there, but not the
|
||||||
|
# Chef one.
|
||||||
|
environment.workdir.join("shell").exist?.should be
|
||||||
|
environment.workdir.join("chef_solo").exist?.should_not be
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Chef Solo Basic Skeleton
|
||||||
|
|
||||||
|
This is a skeleton that contains a basic chef solo setup.
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Just create a file
|
||||||
|
file "/vagrant/chef_solo" do
|
||||||
|
mode 0644
|
||||||
|
content "success"
|
||||||
|
end
|
Loading…
Reference in New Issue