vagrant-r10k 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 960030dda2dd99db2efe4b2af6b221b71eb5d9b6
4
+ data.tar.gz: 348677e6e82c9ee94941072595b082a05b0de1e3
5
+ SHA512:
6
+ metadata.gz: 3efa13ca03e10cce33813c4aa1732a3472fb933f65ca4b1ff0f04965a8f22af460717123343d96d581775f06d6030255a7da05d66a28ed0341c89f77ac388e0b
7
+ data.tar.gz: e14a90077d15f61922e04d04c67526bea681279c1479690758b954ab37d7ce46c44ca31d105f375d8b3693c43b8d134605efe320f21f2c7479829390bf028622
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ vendor
24
+ Vagrantfile
25
+ .vagrant
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gem "vagrant-r10k", path: "."
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jason Antman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Vagrant::R10k
2
+
3
+ vagrant-r10k is a [Vagrant](http://www.vagrantup.com/) 1.2+ middleware plugin to allow you to have just a Puppetfile and
4
+ manifests in your vagrant project, and pull in the required modules via [r10k](https://github.com/adrienthebo/r10k). This
5
+ plugin only works with the 'puppet' provisioner, not a puppet server. It expects you to have a Puppetfile in the same repository
6
+ as your Vagrantfile.
7
+
8
+ ## Installation
9
+
10
+ $ vagrant plugin install vagrant-r10k
11
+
12
+ __Note__ that if you include modules from a (the) forge in your Puppetfile, i.e. in the format
13
+
14
+ mod 'username/modulename'
15
+
16
+ instead of just git references, you will need the ``puppet`` rubygem installed and available. It
17
+ is not included in the Gemfile so that users who only use git references won't have a new/possibly
18
+ conflicting Puppet installation.
19
+
20
+ ## Usage
21
+
22
+ Add the following to your Vagrantfile, before the puppet section:
23
+
24
+ config.r10k.puppet_dir = 'dir' # the parent directory that contains your module directory and Puppetfile
25
+ config.r10k.puppetfile_path = 'dir/Puppetfile' # the path to your Puppetfile, within the repo
26
+
27
+ For the following example directory structure:
28
+
29
+ .
30
+ ├── README.md
31
+ ├── Vagrantfile
32
+ ├── docs
33
+ │   └── foo.md
34
+ ├── puppet
35
+ │   ├── Puppetfile
36
+ │   ├── manifests
37
+ │   │   └── default.pp
38
+ │   └── modules
39
+ └── someproject
40
+ └── foo.something
41
+
42
+ The configuration for r10k and puppet would look like:
43
+
44
+ # r10k plugin to deploy puppet modules
45
+ config.r10k.puppet_dir = "puppet"
46
+ config.r10k.puppetfile_path = "puppet/Puppetfile"
47
+
48
+ # Provision the machine with the appliction
49
+ config.vm.provision "puppet" do |puppet|
50
+ puppet.manifests_path = "puppet/manifests"
51
+ puppet.manifest_file = "default.pp"
52
+ puppet.module_path = "puppet/modules"
53
+ end
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/jantman/vagrant-r10k/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create a new Pull Request
62
+
63
+ ## Testing
64
+
65
+ Still need to write tests... but they'll be using bundler and rspec.
66
+
67
+ ## Debugging
68
+
69
+ Exporting ``VAGRANT_LOG=debug`` will also turn on debug-level logging for r10k.
70
+
71
+ ## Acknowlegements
72
+
73
+ Thanks to the following people:
74
+
75
+ * [@adrienthebo](https://github.com/adrienthebo) for [r10k](https://github.com/adrienthebo/r10k)
76
+ * [@garethr](https://github.com/garethr) for [librarian-puppet-vagrant](https://github.com/garethr/librarian-puppet-vagrant) which inspired this plugin
77
+ * [Alex Kahn](http://akahn.net/) of Paperless Post for his [How to Write a Vagrant Middleware](http://akahn.net/2014/05/05/vagrant-middleware.html) blog post, documenting the new middleware API
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
1
+ require "vagrant-r10k/plugin"
@@ -0,0 +1,38 @@
1
+ module VagrantPlugins
2
+ module R10k
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :puppet_dir
5
+ attr_accessor :puppetfile_path
6
+
7
+ def initialize
8
+ @puppet_dir = UNSET_VALUE
9
+ @puppetfile_path = UNSET_VALUE
10
+ end
11
+
12
+ def validate(machine)
13
+ errors = _detected_errors
14
+
15
+ return {} if puppet_dir == UNSET_VALUE and puppetfile_path == UNSET_VALUE
16
+
17
+ if puppet_dir == UNSET_VALUE
18
+ errors << "config.r10k.puppet_dir must be set"
19
+ return { "vagrant-r10k" => errors }
20
+ end
21
+
22
+ puppet_dir_path = File.join(machine.env.root_path, puppet_dir)
23
+ errors << "puppet_dir directory '#{puppet_dir_path}' does not exist" if !File.directory?(puppet_dir_path)
24
+
25
+ if puppetfile_path == UNSET_VALUE
26
+ errors << "config.r10k.puppetfile_path must be set"
27
+ return { "vagrant-r10k" => errors }
28
+ end
29
+
30
+ puppetfile = File.join(machine.env.root_path, puppetfile_path)
31
+ errors << "puppetfile '#{puppetfile}' does not exist" if !File.file?(puppetfile)
32
+
33
+ { "vagrant-r10k" => errors }
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,118 @@
1
+ require 'r10k/logging'
2
+ require 'vagrant/errors'
3
+
4
+ # this is an ugly monkeypatch, since we're running inside of Vagrant,
5
+ # which has already defined logger but not with the debug1 and debug2 custom levels
6
+ module Log4r
7
+ class Logger
8
+
9
+ def debug1(msg)
10
+ self.debug(msg)
11
+ end
12
+ def debug2(msg)
13
+ self.debug(msg)
14
+ end
15
+ end
16
+ end
17
+
18
+ # patch this so we can get programmatic access to the errors
19
+ module R10K
20
+ class TaskRunner
21
+ def get_errors
22
+ @errors
23
+ end
24
+ end
25
+ end
26
+
27
+ module VagrantPlugins
28
+ module R10k
29
+ class Modulegetter
30
+ include R10K::Logging
31
+ def initialize(app, env)
32
+ @app = app
33
+ end
34
+
35
+ def call(env)
36
+ require 'r10k/puppetfile'
37
+ require 'r10k/task_runner'
38
+ require 'r10k/task/puppetfile'
39
+
40
+ @env = env
41
+ env_dir = @env[:root_path]
42
+
43
+ # since this plugin runs in a hackish way (to force it to be before puppet provisioner's
44
+ # config validation), check here that our config items are set, else bail out
45
+ unset = Vagrant::Plugin::V2::Config::UNSET_VALUE
46
+ if @env[:machine].config.r10k.puppet_dir == unset or @env[:machine].config.r10k.puppetfile_path == unset
47
+ @env[:ui].detail "vagrant-r10k: puppet_dir and/or puppetfile_path not set in config; not running"
48
+ @app.call(env)
49
+ return
50
+ end
51
+
52
+ puppetfile_path = File.join(env_dir, @env[:machine].config.r10k.puppetfile_path)
53
+ module_path = nil
54
+ manifest_file = nil
55
+ manifests_path = nil
56
+ @env[:machine].config.vm.provisioners.each do |prov|
57
+ if prov.name == :puppet
58
+ module_path = File.join(env_dir, prov.config.module_path)
59
+ manifest_file = File.join(env_dir, prov.config.manifest_file)
60
+ manifests_path = File.join(env_dir, prov.config.manifests_path[1])
61
+ end
62
+ end
63
+
64
+ @env[:ui].info "vagrant-r10k: Beginning r10k deploy of puppet modules into #{module_path} using #{puppetfile_path}"
65
+
66
+ if ENV["VAGRANT_LOG"] == "debug"
67
+ R10K::Logging.level = 0
68
+ else
69
+ R10K::Logging.level = 3
70
+ end
71
+
72
+ if !File.file?(puppetfile_path)
73
+ raise ErrorWrapper.new(RuntimeError.new("Puppetfile at #{puppetfile_path} does not exist."))
74
+ end
75
+
76
+ # do the actual module buildout
77
+ runner = R10K::TaskRunner.new([])
78
+ begin
79
+ puppetfile = R10K::Puppetfile.new(File.join(env_dir, @env[:machine].config.r10k.puppet_dir), module_path, puppetfile_path)
80
+ task = R10K::Task::Puppetfile::Sync.new(puppetfile)
81
+ runner.append_task task
82
+ runner.run
83
+ rescue SyntaxError => ex
84
+ @env[:ui].error "Invalid syntax in Puppetfile at #{puppetfile_path}"
85
+ raise ErrorWrapper.new(ex)
86
+ end
87
+ if !runner.succeeded?
88
+ runner.get_errors().each do |error|
89
+ raise ErrorWrapper.new(RuntimeError.new(error[1]))
90
+ end
91
+ end
92
+ @env[:ui].info "vagrant-r10k: Deploy finished"
93
+ @app.call(env)
94
+ end
95
+
96
+ end
97
+
98
+ class ErrorWrapper < ::Vagrant::Errors::VagrantError
99
+ attr_reader :original
100
+
101
+ def initialize(original)
102
+ @original = original
103
+ end
104
+
105
+ def to_s
106
+ "#{original.class}: #{original.to_s}"
107
+ end
108
+
109
+ private
110
+
111
+ def method_missing(fun, *args, &block)
112
+ original.send(fun, *args, &block)
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,32 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ abort "vagrant-r10k must be loaded in a Vagrant environment."
5
+ end
6
+
7
+ if Vagrant::VERSION < "1.2.0"
8
+ raise "The Vagrant r10k plugin is only compatible with Vagrant 1.2+"
9
+ end
10
+
11
+ require "vagrant-r10k/version"
12
+ require "vagrant-r10k/modulegetter"
13
+
14
+ module VagrantPlugins
15
+ module R10k
16
+ class Plugin < Vagrant.plugin('2')
17
+ name "vagrant-r10k"
18
+ description "Retrieve puppet modules based on a Puppetfile"
19
+
20
+ action_hook "vagrant-r10k" do |hook|
21
+ hook.before Vagrant::Action::Builtin::Provision, Modulegetter
22
+ hook.before Vagrant::Action::Builtin::ConfigValidate, Modulegetter
23
+ end
24
+
25
+ config "r10k" do
26
+ require_relative "config"
27
+ Config
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module R10k
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-r10k/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-r10k"
8
+ spec.version = VagrantPlugins::R10k::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["Jason Antman"]
11
+ spec.email = ["jason@jasonantman.com"]
12
+ spec.summary = %q{Vagrant middleware plugin to retrieve puppet modules using r10k.}
13
+ spec.description = %q{Vagrant middleware plugin to allow you to have just a Puppetfile and manifests in your vagrant project, and pull in the required modules via r10k.}
14
+ spec.homepage = "https://github.com/jantman/vagrant-r10k"
15
+ spec.license = "Apache-2.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "r10k", "~> 1.2.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-r10k
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Antman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: r10k
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Vagrant middleware plugin to allow you to have just a Puppetfile and
56
+ manifests in your vagrant project, and pull in the required modules via r10k.
57
+ email:
58
+ - jason@jasonantman.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/vagrant-r10k.rb
69
+ - lib/vagrant-r10k/config.rb
70
+ - lib/vagrant-r10k/modulegetter.rb
71
+ - lib/vagrant-r10k/plugin.rb
72
+ - lib/vagrant-r10k/version.rb
73
+ - vagrant-r10k.gemspec
74
+ homepage: https://github.com/jantman/vagrant-r10k
75
+ licenses:
76
+ - Apache-2.0
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Vagrant middleware plugin to retrieve puppet modules using r10k.
98
+ test_files: []