provisioners/chef: Add `chef_zero` provisioner

Add Chef Zero provisioner using `local_mode` configuration for
chef-solo/chef-client.
This commit is contained in:
Teemu Matilainen 2014-05-20 00:05:46 +03:00 committed by Seth Vargo
parent 8614591f96
commit dec5dcdda3
5 changed files with 98 additions and 17 deletions

View File

@ -0,0 +1,30 @@
require_relative "chef_solo"
module VagrantPlugins
module Chef
module Config
class ChefZero < ChefSolo
attr_accessor :nodes_path
def initialize
super
@nodes_path = UNSET_VALUE
end
def finalize!
super
@nodes_path = [] if @nodes_path == UNSET_VALUE
# Make sure the path is an array.
@nodes_path = prepare_folders_config(@nodes_path)
end
def validate(machine)
{ "Chef Zero provisioner" => super["chef solo provisioner"] }
end
end
end
end
end

View File

@ -24,6 +24,11 @@ module VagrantPlugins
Config::ChefClient
end
config(:chef_zero, :provisioner) do
require File.expand_path("../config/chef_zero", __FILE__)
Config::ChefZero
end
provisioner(:chef_solo) do
require File.expand_path("../provisioner/chef_solo", __FILE__)
Provisioner::ChefSolo
@ -33,6 +38,11 @@ module VagrantPlugins
require File.expand_path("../provisioner/chef_client", __FILE__)
Provisioner::ChefClient
end
provisioner(:chef_zero) do
require File.expand_path("../provisioner/chef_zero", __FILE__)
Provisioner::ChefZero
end
end
end
end

View File

@ -19,6 +19,7 @@ module VagrantPlugins
def initialize(machine, config)
super
@logger = Log4r::Logger.new("vagrant::provisioners::chef_solo")
@shared_folders = []
end
def configure(root_config)
@ -36,13 +37,11 @@ module VagrantPlugins
def provision
# Verify that the proper shared folders exist.
check = []
[@cookbook_folders, @role_folders, @data_bags_folders, @environments_folders].each do |folders|
folders.each do |type, local_path, remote_path|
# We only care about checking folders that have a local path, meaning
# they were shared from the local machine, rather than assumed to
# exist on the VM.
check << remote_path if local_path
end
@shared_folders.each do |type, local_path, remote_path|
# We only care about checking folders that have a local path, meaning
# they were shared from the local machine, rather than assumed to
# exist on the VM.
check << remote_path if local_path
end
chown_provisioning_folder
@ -113,20 +112,21 @@ module VagrantPlugins
root_config.vm.synced_folder(local_path, remote_path, opts)
end
end
@shared_folders += folders
end
def setup_solo_config
cookbooks_path = guest_paths(@cookbook_folders)
roles_path = guest_paths(@role_folders)
data_bags_path = guest_paths(@data_bags_folders).first
environments_path = guest_paths(@environments_folders).first
setup_config("provisioners/chef_solo/solo", "solo.rb", {
cookbooks_path: cookbooks_path,
setup_config("provisioners/chef_solo/solo", "solo.rb", solo_config)
end
def solo_config
{
cookbooks_path: guest_paths(@cookbook_folders),
recipe_url: @config.recipe_url,
roles_path: roles_path,
data_bags_path: data_bags_path,
environments_path: environments_path,
})
roles_path: guest_paths(@role_folders),
data_bags_path: guest_paths(@data_bags_folders).first,
environments_path: guest_paths(@environments_folders).first
}
end
def run_chef_solo

View File

@ -0,0 +1,34 @@
require "log4r"
require_relative "chef_solo"
module VagrantPlugins
module Chef
module Provisioner
# This class implements provisioning via chef-zero.
class ChefZero < ChefSolo
attr_reader :node_folders
def initialize(machine, config)
super
@logger = Log4r::Logger.new("vagrant::provisioners::chef_zero")
end
def configure(root_config)
super
@node_folders = expanded_folders(@config.nodes_path, "nodes")
share_folders(root_config, "csn", @node_folders)
end
def solo_config
super.merge(
local_mode: true,
node_path: guest_paths(@node_folders).first
)
end
end
end
end
end

View File

@ -32,6 +32,13 @@ environment_path <%= environments_path.inspect %>
environment "<%= environment %>"
<% end -%>
<% if local_mode -%>
local_mode true
<% end -%>
<% if node_path -%>
node_path <%= node_path.inspect %>
<% end -%>
http_proxy <%= http_proxy.inspect %>
http_proxy_user <%= http_proxy_user.inspect %>
http_proxy_pass <%= http_proxy_pass.inspect %>