vagrant-ohai 0.1.1

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmFhMTIwYjcwYWUyNmY3NmYzMTU4NmEzZTY2MmJkMTNhYzEzY2IzZA==
5
+ data.tar.gz: !binary |-
6
+ M2Q2MzNhYTU0NjNiNDYzOTkwODY5OTAyNTEwNzhkODY3MzkyZWIzOA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MzQ1MDU2YzUwN2RjZWUzOGIyZDZjYzQ1ZTk3ZWNkZjk5OTc5OGNjZThhMTgx
10
+ YzdiYTM0ZGIzYjA2ODA3ZmI4ZDc2YTk2Zjc3OTMyNDQ3ODI1YmMwOGQ2Y2Yy
11
+ YTA2ZGZiNjU2OGZmNDEzMTM5ODE4ODBmOWJhYjQxOTJjNDk5MWY=
12
+ data.tar.gz: !binary |-
13
+ NDU1ZDQwMGYzMWE4MTc0ZmRlNDcwMGYzZDVlM2M0YzU3ODRjMzAxYTNjOWQ1
14
+ Zjc1ZmJhYzhjNzg0NDgxMmI2ZTU3ZTY5N2MwYjRkZDFmZDIzZDMyMzIwNmM0
15
+ MDRmMTQ2MzVjYjNlNDAyMDAyYzI3ZWExMDI2NWFlZDQ2ODZkMDI=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-ohai.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Avishai Ish-Shalom
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,25 @@
1
+ # Vagrant::Ohai
2
+
3
+ This is a [vagrant](http://vagrantup.com) plugin which installs an Ohai plugin providing network information to Chef.
4
+ In particular, the ipaddress is set to the private network defined in vagrant, if one is present.
5
+
6
+ ## Installation
7
+
8
+ vagrant plugin install vagrant-ohai
9
+
10
+
11
+ ## Usage
12
+
13
+ The plugin will automatcially activate when using the `:chef_solo` or `:chef_client` provisioners. If you want to disable it, put `config.ohai.enable = false` in your Vagrantfile.
14
+
15
+ ## Compatability
16
+
17
+ This plugin works with Vagrant 1.2.3 and above.
18
+
19
+ ## Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ hints = hint?("vagrant")
2
+
3
+ provides "vagrant"
4
+ provides "cloud"
5
+
6
+ vagrant Mash.new
7
+ cloud Mash.new
8
+
9
+ if hints
10
+ vagrant.merge!(hints)
11
+ require_plugin "cloud"
12
+ if vagrant.has_key? :private_ipv4
13
+ cloud[:local_ipv4] = vagrant[:private_ipv4]
14
+ ipaddress vagrant[:private_ipv4]
15
+ end
16
+ cloud[:provider] = "vagrant"
17
+ end
@@ -0,0 +1 @@
1
+ require 'vagrant-ohai/vagrant-ohai.rb'
@@ -0,0 +1,44 @@
1
+ require 'vagrant-ohai/helpers'
2
+
3
+ module VagrantPlugins
4
+ module Ohai
5
+ class ActionConfigureChef
6
+ include VagrantPlugins::Ohai::Helpers
7
+
8
+ def initialize(app, env)
9
+ @app = app
10
+ @env = env
11
+ @machine = env[:machine]
12
+ @tempfiles = []
13
+ register_custom_chef_config
14
+ end
15
+
16
+ def call(env)
17
+ @app.call(env)
18
+ end
19
+
20
+ private
21
+ def ohai_custom_config(current_conf)
22
+ tmp = Tempfile.new(["chef-custom-config", ".rb"])
23
+ tmp.puts 'Ohai::Config[:plugin_path] << "/etc/chef/ohai_plugins"'
24
+ tmp.write(File.read(current_conf)) if current_conf
25
+ tmp.close
26
+ # retain a reference to prevent tempfile from being auto cleaned up
27
+ @tempfiles << tmp
28
+ tmp
29
+ end
30
+
31
+ def register_custom_chef_config
32
+ chef_provisioners.each do |provisioner|
33
+ if provisioner.config.respond_to? :custom_config_path and not provisioner.config.custom_config_path == Plugin::UNSET_VALUE
34
+ current_custom_config_path = provisioner.config.custom_config_path
35
+ else
36
+ current_custom_config_path = nil
37
+ end
38
+ custom_config = ohai_custom_config(current_custom_config_path)
39
+ provisioner.config.instance_variable_set("@custom_config_path", custom_config.path)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,60 @@
1
+ require 'vagrant-ohai/helpers'
2
+
3
+ module VagrantPlugins
4
+ module Ohai
5
+ class ActionInstallOhaiPlugin
6
+ OHAI_PLUGIN_PATH = File.expand_path("../../ohai/vagrant.rb", __FILE__)
7
+
8
+ include VagrantPlugins::Ohai::Helpers
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @env = env
13
+ @machine = env[:machine]
14
+ end
15
+
16
+ def call(env)
17
+ @app.call(env)
18
+ return unless @machine.communicate.ready?
19
+
20
+ if chef_provisioners.any?
21
+ @machine.ui.info("Installing Ohai plugin")
22
+ create_ohai_folders
23
+ copy_ohai_plugin
24
+ hint_ohai
25
+ end
26
+ end
27
+
28
+ private
29
+ def create_ohai_folders
30
+ @machine.communicate.tap do |comm|
31
+ comm.sudo("mkdir -p /etc/chef/ohai/hints")
32
+ comm.sudo("mkdir -p /etc/chef/ohai_plugins")
33
+ comm.sudo("chown -R #{@machine.ssh_info[:username]} /etc/chef/ohai/hints /etc/chef/ohai_plugins")
34
+ end
35
+ end
36
+
37
+ def private_ipv4
38
+ @private_ipv4 ||= @machine.config.vm.networks.find {|network| network.first == :private_network}[1][:ip]
39
+ end
40
+
41
+ def vagrant_info
42
+ info = {}
43
+ info[:private_ipv4] = private_ipv4 if private_ipv4
44
+ info
45
+ end
46
+
47
+ def hint_ohai
48
+ hint_file = Tempfile.new(["vagrant-ohai", ".json"])
49
+ hint_file.write(vagrant_info.to_json)
50
+ hint_file.close
51
+ @machine.communicate.upload(hint_file.path, "/etc/chef/ohai/hints/vagrant.json")
52
+ end
53
+
54
+ def copy_ohai_plugin
55
+ @machine.communicate.upload(OHAI_PLUGIN_PATH, "/etc/chef/ohai_plugins/vagrant.rb")
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ module VagrantPlugins
2
+ module Ohai
3
+ class Config < Vagrant.plugin(2, :config)
4
+ attr_accessor :enable
5
+
6
+ def initialize
7
+ @enable = UNSET_VALUE
8
+ end
9
+ def finalize!
10
+ @enable = true if @enable == UNSET_VALUE
11
+ end
12
+
13
+ def validate(machine)
14
+ case @enable
15
+ when TrueClass, FalseClass
16
+ {}
17
+ else
18
+ {"enable" => ["enable must be true or false"] }
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module VagrantPlugins
2
+ module Ohai
3
+ module Helpers
4
+
5
+ def chef_provisioners
6
+ @machine.config.vm.provisioners.find_all {|provisioner|
7
+ [:chef_client, :chef_solo].include? provisioner.name }
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Ohai
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require "vagrant-ohai/version"
2
+ require "vagrant/plugin"
3
+
4
+ raise RuntimeException, "vagrant-ohai will only work with Vagrant 1.2.3 and above!" if Vagrant::VERSION <= "1.2.3"
5
+
6
+ module VagrantPlugins
7
+ module Ohai
8
+ class Plugin < Vagrant.plugin("2")
9
+ name "vagrant-ohai"
10
+ description <<-DESC
11
+ This plugin ensures ipaddress and cloud attributes in Chef
12
+ correspond to Vagrant's private network
13
+ DESC
14
+
15
+ hook_block = proc do |hook|
16
+ require_relative 'action_install_ohai_plugin'
17
+ require_relative 'action_configure_chef'
18
+ hook.after(Vagrant::Action::Builtin::Provision, ActionInstallOhaiPlugin)
19
+ hook.before(Vagrant::Action::Builtin::ConfigValidate, ActionConfigureChef)
20
+ end
21
+
22
+ action_hook(:install_ohai_plugin, :machine_action_provision, &hook_block)
23
+ action_hook(:install_ohai_plugin, :machine_action_up, &hook_block)
24
+
25
+ config(:ohai) do
26
+ require_relative "config"
27
+ Config
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Ohai
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-ohai/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-ohai"
8
+ spec.version = VagrantPlugins::Ohai::VERSION
9
+ spec.authors = ["Avishai Ish-Shalom"]
10
+ spec.email = ["avishai@fewbytes.com"]
11
+ spec.description = %q{Vagrant plugin which installs an Ohai plugn to properly detect private ipaddress}
12
+ spec.summary = %q{Vagrant plugin which installs an Ohai plugn to properly detect private ipaddress}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ohai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Avishai Ish-Shalom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Vagrant plugin which installs an Ohai plugn to properly detect private
42
+ ipaddress
43
+ email:
44
+ - avishai@fewbytes.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/ohai/vagrant.rb
55
+ - lib/vagrant-ohai.rb
56
+ - lib/vagrant-ohai/action_configure_chef.rb
57
+ - lib/vagrant-ohai/action_install_ohai_plugin.rb
58
+ - lib/vagrant-ohai/config.rb
59
+ - lib/vagrant-ohai/helpers.rb
60
+ - lib/vagrant-ohai/ohai/version.rb
61
+ - lib/vagrant-ohai/vagrant-ohai.rb
62
+ - lib/vagrant-ohai/version.rb
63
+ - vagrant-ohai.gemspec
64
+ homepage: ''
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.0.5
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Vagrant plugin which installs an Ohai plugn to properly detect private ipaddress
88
+ test_files: []