-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge in 'flexible-provisioning' which supports abstracted provisione…
…rs, chef server, additional chef solo features, and better chef configuration overall. Also includes pluggable configuration keys.
- Loading branch information
Showing
19 changed files
with
867 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Vagrant | ||
module Provisioners | ||
# The base class for a "provisioner." A provisioner is responsible for | ||
# provisioning a Vagrant system. This has been abstracted out to provide | ||
# support for multiple solutions such as Chef Solo, Chef Client, and | ||
# Puppet. | ||
class Base | ||
include Vagrant::Util | ||
|
||
# This is the method called to "prepare" the provisioner. This is called | ||
# before any actions are run by the action runner (see {Vagrant::Actions::Runner}). | ||
# This can be used to setup shared folders, forward ports, etc. Whatever is | ||
# necessary on a "meta" level. | ||
def prepare; end | ||
|
||
# This is the method called to provision the system. This method | ||
# is expected to do whatever necessary to provision the system (create files, | ||
# SSH, etc.) | ||
def provision!; end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
module Vagrant | ||
module Provisioners | ||
# This class is a base class where the common functinality shared between | ||
# chef-solo and chef-client provisioning are stored. This is **not an actual | ||
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used. | ||
class Chef < Base | ||
# This is the configuration which is available through `config.chef` | ||
class ChefConfig < Vagrant::Config::Base | ||
# Chef server specific config | ||
attr_accessor :chef_server_url | ||
attr_accessor :validation_key_path | ||
attr_accessor :validation_client_name | ||
attr_accessor :client_key_path | ||
|
||
# Chef solo specific config | ||
attr_accessor :cookbooks_path | ||
|
||
# Shared config | ||
attr_accessor :provisioning_path | ||
attr_accessor :json | ||
|
||
def initialize | ||
@validation_client_name = "chef-validator" | ||
@client_key_path = "/etc/chef/client.pem" | ||
|
||
@cookbooks_path = "cookbooks" | ||
@provisioning_path = "/tmp/vagrant-chef" | ||
@json = { | ||
:instance_role => "vagrant", | ||
:run_list => ["recipe[vagrant_main]"] | ||
} | ||
end | ||
|
||
# Returns the run list for the provisioning | ||
def run_list | ||
json[:run_list] | ||
end | ||
|
||
# Sets the run list to the specified value | ||
def run_list=(value) | ||
json[:run_list] = value | ||
end | ||
|
||
# Adds a recipe to the run list | ||
def add_recipe(name) | ||
name = "recipe[#{name}]" unless name =~ /^recipe\[(.+?)\]$/ | ||
run_list << name | ||
end | ||
|
||
# Adds a role to the run list | ||
def add_role(name) | ||
name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/ | ||
run_list << name | ||
end | ||
|
||
def to_json | ||
# Overridden so that the 'json' key could be removed, since its just | ||
# merged into the config anyways | ||
data = instance_variables_hash | ||
data.delete(:json) | ||
data.to_json | ||
end | ||
end | ||
|
||
# Tell the Vagrant configure class about our custom configuration | ||
Config.configures :chef, ChefConfig | ||
|
||
def prepare | ||
raise Actions::ActionException.new("Vagrant::Provisioners::Chef is not a valid provisioner! Use ChefSolo or ChefServer instead.") | ||
end | ||
|
||
def chown_provisioning_folder | ||
logger.info "Setting permissions on chef provisioning folder..." | ||
SSH.execute do |ssh| | ||
ssh.exec!("sudo mkdir -p #{Vagrant.config.chef.provisioning_path}") | ||
ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}") | ||
end | ||
end | ||
|
||
def setup_json | ||
logger.info "Generating chef JSON and uploading..." | ||
|
||
# Set up initial configuration | ||
data = { | ||
:config => Vagrant.config, | ||
:directory => Vagrant.config.vm.project_directory, | ||
} | ||
|
||
# And wrap it under the "vagrant" namespace | ||
data = { :vagrant => data } | ||
|
||
# Merge with the "extra data" which isn't put under the | ||
# vagrant namespace by default | ||
data.merge!(Vagrant.config.chef.json) | ||
|
||
json = data.to_json | ||
|
||
SSH.upload!(StringIO.new(json), File.join(Vagrant.config.chef.provisioning_path, "dna.json")) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.