From dec5dcdda3f79f2908d05ce84eb77991a999527f Mon Sep 17 00:00:00 2001 From: Teemu Matilainen Date: Tue, 20 May 2014 00:05:46 +0300 Subject: [PATCH] provisioners/chef: Add `chef_zero` provisioner Add Chef Zero provisioner using `local_mode` configuration for chef-solo/chef-client. --- plugins/provisioners/chef/config/chef_zero.rb | 30 ++++++++++++++++ plugins/provisioners/chef/plugin.rb | 10 ++++++ .../chef/provisioner/chef_solo.rb | 34 +++++++++---------- .../chef/provisioner/chef_zero.rb | 34 +++++++++++++++++++ templates/provisioners/chef_solo/solo.erb | 7 ++++ 5 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 plugins/provisioners/chef/config/chef_zero.rb create mode 100644 plugins/provisioners/chef/provisioner/chef_zero.rb diff --git a/plugins/provisioners/chef/config/chef_zero.rb b/plugins/provisioners/chef/config/chef_zero.rb new file mode 100644 index 000000000..ca7c5618b --- /dev/null +++ b/plugins/provisioners/chef/config/chef_zero.rb @@ -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 diff --git a/plugins/provisioners/chef/plugin.rb b/plugins/provisioners/chef/plugin.rb index afe068047..0a771f300 100644 --- a/plugins/provisioners/chef/plugin.rb +++ b/plugins/provisioners/chef/plugin.rb @@ -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 diff --git a/plugins/provisioners/chef/provisioner/chef_solo.rb b/plugins/provisioners/chef/provisioner/chef_solo.rb index bf66c99d5..e93ba7f5b 100644 --- a/plugins/provisioners/chef/provisioner/chef_solo.rb +++ b/plugins/provisioners/chef/provisioner/chef_solo.rb @@ -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 diff --git a/plugins/provisioners/chef/provisioner/chef_zero.rb b/plugins/provisioners/chef/provisioner/chef_zero.rb new file mode 100644 index 000000000..8ccae6130 --- /dev/null +++ b/plugins/provisioners/chef/provisioner/chef_zero.rb @@ -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 diff --git a/templates/provisioners/chef_solo/solo.erb b/templates/provisioners/chef_solo/solo.erb index fd52fff91..b7d08a65b 100644 --- a/templates/provisioners/chef_solo/solo.erb +++ b/templates/provisioners/chef_solo/solo.erb @@ -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 %>