-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
43 changed files
with
1,666 additions
and
590 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ vendor | |
coverage | ||
results.xml | ||
spec/boxes | ||
acceptance.out |
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,41 @@ | ||
require 'vagrant/action' | ||
require_relative '../helpers' | ||
|
||
module VagrantPlugins | ||
module R10k | ||
module Action | ||
class Base | ||
|
||
include R10K::Logging | ||
|
||
def self.validate | ||
Vagrant::Action::Builder.new.tap do |b| | ||
b.use Action::Validate | ||
end | ||
end | ||
|
||
def self.deploy | ||
Vagrant::Action::Builder.new.tap do |b| | ||
b.use Action::Validate | ||
b.use Action::Deploy | ||
end | ||
end | ||
|
||
include VagrantPlugins::R10k::Helpers | ||
|
||
def initialize(app, env) | ||
@app = app | ||
@env = env | ||
klass = self.class.name.downcase.split('::').last | ||
@logger = Log4r::Logger.new("vagrant::r10k::#{klass}") | ||
if ENV["VAGRANT_LOG"] == "debug" | ||
R10K::Logging.level = 0 | ||
@logger.level = 0 | ||
else | ||
R10K::Logging.level = 3 | ||
end | ||
end | ||
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,82 @@ | ||
require_relative 'base' | ||
|
||
module VagrantPlugins | ||
module R10k | ||
module Action | ||
class Deploy < Base | ||
|
||
def call(env) | ||
@logger.debug "vagrant::r10k::deploy called" | ||
|
||
if !r10k_enabled?(env) | ||
env[:ui].info "vagrant-r10k not configured; skipping" | ||
return @app.call(env) | ||
end | ||
|
||
if !provision_enabled?(env) | ||
env[:ui].info "provisioning disabled; skipping vagrant-r10k" | ||
return @app.call(env) | ||
end | ||
|
||
# get our config | ||
config = r10k_config(env) | ||
if config.nil? | ||
@logger.info "vagrant::r10k::deploy got nil configuration" | ||
raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k configuration error; cannot continue")) | ||
end | ||
@logger.debug("vagrant::r10k::deploy: env_dir_path=#{config[:env_dir_path]}") | ||
@logger.debug("vagrant::r10k::deploy: puppetfile_path=#{config[:puppetfile_path]}") | ||
@logger.debug("vagrant::r10k::deploy: module_path=#{config[:module_path]}") | ||
@logger.debug("vagrant::r10k::deploy: manifests=#{config[:manifests]}") | ||
@logger.debug("vagrant::r10k::deploy: manifest_file=#{config[:manifest_file]}") | ||
@logger.debug("vagrant::r10k::deploy: puppet_dir=#{config[:puppet_dir]}") | ||
|
||
deploy(env, config) | ||
|
||
@app.call(env) | ||
end | ||
|
||
def deploy(env, config) | ||
@logger.debug("vagrant::r10k::deploy.deploy called") | ||
require 'r10k/task_runner' | ||
require 'r10k/task/puppetfile' | ||
|
||
env[:ui].info "vagrant-r10k: Beginning r10k deploy of puppet modules into #{config[:module_path]} using #{config[:puppetfile_path]}" | ||
|
||
if ENV["VAGRANT_LOG"] == "debug" | ||
R10K::Logging.level = 0 | ||
else | ||
R10K::Logging.level = 3 | ||
end | ||
|
||
if !File.file?(config[:puppetfile_path]) | ||
raise ErrorWrapper.new(RuntimeError.new("Puppetfile at #{config[:puppetfile_path]} does not exist.")) | ||
end | ||
|
||
# do the actual module buildout | ||
runner = R10K::TaskRunner.new([]) | ||
begin | ||
puppetfile = get_puppetfile(config) | ||
@logger.debug("vagrant-r10k: creating Puppetfile::Sync task") | ||
task = R10K::Task::Puppetfile::Sync.new(puppetfile) | ||
@logger.debug("vagrant-r10k: appending task to runner queue") | ||
runner.append_task task | ||
@logger.debug("vagrant-r10k: running sync task") | ||
runner.run | ||
@logger.debug("vagrant-r10k: sync task complete") | ||
rescue SyntaxError => ex | ||
@env[:ui].error "Invalid syntax in Puppetfile at #{config[:puppetfile_path]}" | ||
raise ErrorWrapper.new(ex) | ||
end | ||
if !runner.succeeded? | ||
runner.get_errors().each do |error| | ||
raise ErrorWrapper.new(RuntimeError.new(error[1])) | ||
end | ||
end | ||
@env[:ui].info "vagrant-r10k: Deploy finished" | ||
@app.call(env) | ||
end | ||
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,44 @@ | ||
require_relative 'base' | ||
|
||
module VagrantPlugins | ||
module R10k | ||
module Action | ||
class Validate < Base | ||
|
||
def call(env) | ||
@logger.debug "vagrant::r10k::validate called" | ||
|
||
if !r10k_enabled?(env) | ||
env[:ui].info "vagrant-r10k not configured; skipping" | ||
return @app.call(env) | ||
end | ||
|
||
if !provision_enabled?(env) | ||
env[:ui].info "provisioning disabled; skipping vagrant-r10k" | ||
return @app.call(env) | ||
end | ||
|
||
config = r10k_config(env) | ||
if config.nil? | ||
@logger.info "vagrant::r10k::deploy got nil configuration" | ||
raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k configuration error; cannot continue")) | ||
end | ||
|
||
puppetfile = get_puppetfile(config) | ||
|
||
# validate puppetfile | ||
@logger.debug "vagrant::r10k::validate: validating Puppetfile at #{config[:puppetfile_path]}" | ||
begin | ||
puppetfile.load | ||
rescue Exception => ex | ||
@logger.error "ERROR: Puppetfile bad syntax" | ||
raise ErrorWrapper.new(RuntimeError.new(ex)) | ||
end | ||
|
||
@app.call(env) | ||
end | ||
|
||
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
Oops, something went wrong.