vagrant-hiera 0.1.4

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.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-hiera.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Glenn Poston
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,42 @@
1
+ # Vagrant::Hiera
2
+
3
+ TODO: Configures puppet-heira on your vagrant box
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vagrant-hiera'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vagrant-hiera
18
+
19
+ ## Usage
20
+
21
+ Create a [hiera.yaml](https://github.com/puppetlabs/hiera-puppet#module-user) file on your host with the datadir pointing to `/tmp/vagrant-hiera/data`
22
+
23
+ :json:
24
+ :datadir: /var/lib/hiera
25
+
26
+ Add the following to your VagrantFile:
27
+
28
+ config.hiera.config_path = 'host/path/to/the/directory/that/contains/hiera.yaml'
29
+ config.hiera.config_file = 'hiera.yaml'
30
+ config.hiera.data_path = 'host/path/to/hiera-data'
31
+
32
+ And then...
33
+
34
+ `vagrant up`
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,39 @@
1
+ module VagrantHiera
2
+
3
+ class Config < Vagrant::Config::Base
4
+ attr_accessor :config_path
5
+ attr_accessor :guest_config_path
6
+ attr_accessor :config_file
7
+ attr_accessor :data_path
8
+ attr_accessor :guest_data_path
9
+
10
+ def guest_config_path
11
+ @guest_config_path.nil? ? (@guest_config_path = '/tmp/vagrant-hiera/config') : @guest_config_path
12
+ end
13
+
14
+ def guest_data_path
15
+ @guest_data_path.nil? ? (@guest_data_path = '/tmp/vagrant-hiera/data') : @guest_data_path
16
+ end
17
+
18
+ def config_path
19
+ File.expand_path(@config_path) rescue ''
20
+ end
21
+
22
+ def data_path
23
+ File.expand_path(@data_path) rescue ''
24
+ end
25
+
26
+ def set?
27
+ config_path || config_file || data_path
28
+ end
29
+
30
+ def validate(env, errors)
31
+ errors.add("Config path can not be empty") if config_path.empty?
32
+ errors.add("Config file can not be empty") if config_file.empty?
33
+ errors.add("Data path can not be empty") if data_path.empty?
34
+ config = File.join("#{config_path}", "#{config_file}")
35
+ errors.add("#{config} does not exist.") unless File.exists?(config)
36
+ errors.add("#{data_path} does not exist.") unless File.exists?("#{data_path}")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ module VagrantHiera
2
+ module Middleware
3
+
4
+ class Prepare
5
+ def initialize(app, env)
6
+ @app = app
7
+ @env = env
8
+ end
9
+
10
+ def call(env)
11
+ @env = env
12
+ if @env[:vm].config.hiera.set?
13
+ create_shared_folders
14
+ end
15
+ @app.call(env)
16
+ end
17
+
18
+ def create_shared_folders
19
+ @env[:ui].info I18n.t('vagrant.plugins.hiera.middleware.prepare.shared_folders')
20
+ folders = [{:name => 'vagrant-hiera-config', :hostpath => @env[:vm].config.hiera.config_path},
21
+ {:name => 'vagrant-hiera-data', :hostpath => @env[:vm].config.hiera.data_path}]
22
+ @env[:vm].driver.share_folders(folders)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,47 @@
1
+ module VagrantHiera
2
+ module Middleware
3
+
4
+ class Setup
5
+ def initialize(app, env)
6
+ @app = app
7
+ @env = env
8
+ end
9
+
10
+ def call(env)
11
+ @env = env
12
+ if @env[:vm].config.hiera.set?
13
+ install_puppet_hiera unless puppet_hiera_installed?
14
+ create_shared_folders
15
+ create_symlink_to_hiera_config
16
+ end
17
+ @app.call(env)
18
+ end
19
+
20
+ def puppet_hiera_installed?
21
+ installed = ( @env[:vm].channel.execute("gem list | grep hiera-puppet", :error_check => false) == 0 )
22
+ @env[:ui].success I18n.t('vagrant.plugins.hiera.middleware.setup.hiera_installed') if installed
23
+ installed
24
+ end
25
+
26
+ def install_puppet_hiera
27
+ @env[:ui].warn I18n.t('vagrant.plugins.hiera.middleware.setup.installing_hiera')
28
+ @env[:vm].channel.sudo("gem install hiera-puppet")
29
+ end
30
+
31
+ def create_shared_folders
32
+ @env[:ui].info I18n.t('vagrant.plugins.hiera.middleware.setup.shared_folders')
33
+ data = {}
34
+ data[:owner] ||= @env[:vm].config.ssh.username
35
+ data[:group] ||= @env[:vm].config.ssh.username
36
+ @env[:vm].guest.mount_shared_folder('vagrant-hiera-config', @env[:vm].config.hiera.guest_config_path, data)
37
+ @env[:vm].guest.mount_shared_folder('vagrant-hiera-data', @env[:vm].config.hiera.guest_data_path, data)
38
+ end
39
+
40
+ def create_symlink_to_hiera_config
41
+ @env[:ui].info I18n.t('vagrant.plugins.hiera.middleware.setup.installing_hiera_config')
42
+ @env[:vm].channel.sudo("mkdir -p /etc/puppet")
43
+ @env[:vm].channel.sudo("ln -fs #{@env[:vm].config.hiera.guest_config_path}/#{@env[:vm].config.hiera.config_file} /etc/puppet/hiera.yaml")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Hiera
3
+ VERSION = "0.1.4"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'vagrant'
2
+ require 'vagrant-hiera/middleware/prepare'
3
+ require 'vagrant-hiera/middleware/setup'
4
+ require 'vagrant-hiera/config'
5
+
6
+
7
+ Vagrant.config_keys.register(:hiera) { VagrantHiera::Config }
8
+
9
+ Vagrant.actions[:start].insert_after Vagrant::Action::VM::ShareFolders, VagrantHiera::Middleware::Prepare
10
+ Vagrant.actions[:start].use VagrantHiera::Middleware::Setup
11
+
12
+ I18n.load_path << File.expand_path("../../locales/en.yml", __FILE__)
@@ -0,0 +1 @@
1
+ require 'vagrant-hiera'
data/locales/en.yml ADDED
@@ -0,0 +1,12 @@
1
+ en:
2
+ vagrant:
3
+ plugins:
4
+ hiera:
5
+ middleware:
6
+ prepare:
7
+ shared_folders: "Creating hiera shared folders metadata..."
8
+ setup:
9
+ hiera_installed: "puppet-hiera is installed"
10
+ installing_hiera: "Installing puppet-hiera"
11
+ installing_hiera_config: "Adding hiera config file"
12
+ shared_folders: "Adding hiera data folder"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/vagrant-hiera/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Glenn Poston"]
6
+ gem.email = ["gposton1040@gmail.com"]
7
+ gem.description = %q{Configure a vagrant box to use puppet-hiera}
8
+ gem.summary = %q{Configure a vagrant box to use puppet-hiera}
9
+ gem.homepage = "https://github.com/gposton/vagrant-hiera"
10
+
11
+ gem.add_development_dependency "vagrant"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "vagrant-hiera"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Vagrant::Hiera::VERSION
19
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-hiera
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Glenn Poston
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vagrant
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Configure a vagrant box to use puppet-hiera
31
+ email:
32
+ - gposton1040@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - lib/vagrant-hiera.rb
42
+ - lib/vagrant-hiera/config.rb
43
+ - lib/vagrant-hiera/middleware/prepare.rb
44
+ - lib/vagrant-hiera/middleware/setup.rb
45
+ - lib/vagrant-hiera/version.rb
46
+ - lib/vagrant_init.rb
47
+ - locales/en.yml
48
+ - vagrant-hiera.gemspec
49
+ homepage: https://github.com/gposton/vagrant-hiera
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Configure a vagrant box to use puppet-hiera
73
+ test_files: []