vagrant-ohai2 0.1.14

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: dea985e2ede58fe7c113fe6a34d6edca8279c493
4
+ data.tar.gz: df0404fd9b1a5b84a1781e883710beb48432a069
5
+ SHA512:
6
+ metadata.gz: cc22f0bc06bc9f6be01f6bd92f2e93dc33c27c23826fe767ab030d75f7678566ee8ff13e07420e431f7039caeafede456e3c26f6f102f336a44ea581c86aa361
7
+ data.tar.gz: 34c9bbd6be275cd8d93734bdbb64c79edde2e01ebe2329d2bf9968df4fdccbd76e1d46f9595e43e349d4c9a674e47d5eabd9274a0e5b23272c0dbf70768ccfe4
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-ohai2.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,35 @@
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
+ This is a fork of [Avishai Ish-Shalom](https://github.com/avishai-ish-shalom/vagrant-ohai).
7
+
8
+ ## Installation
9
+
10
+ vagrant plugin install vagrant-ohai
11
+
12
+ ## Usage
13
+
14
+ The plugin will automatically activate when using the `:chef_solo`, `:chef_zero`, `:chef_apply`, `:chef_client` or `:shell` provisioners. If you want to disable it, put `config.ohai.enable = false` in your Vagrantfile.
15
+ If you wish to use a primary nic which is not a private network, e.g. when using a bridge, set the `primary_nic` option:
16
+
17
+ config.ohai.primary_nic = "eth1"
18
+
19
+ To activate custom plugin support put `config.ohai.plugins_dir = <full_path_to_plugins_dir>` in your Vagrantfile
20
+
21
+ config.ohai.plugins_dir = "/var/ohai/custom_plugins"
22
+
23
+ ## Compatibility
24
+
25
+ This plugin works with Vagrant 1.2.3 and above.
26
+
27
+ It has only been tested on VirtualBox but should also work with other Vagrant providers.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,64 @@
1
+ Ohai.plugin(:VboxIpaddress) do
2
+
3
+ def read_json(filename)
4
+ if defined? FFI_Yajl::Parser
5
+ FFI_Yajl::Parser.new.parse(IO.read(filename))
6
+ else
7
+ require 'json'
8
+ JSON.parse(IO.read(filename))
9
+ end
10
+ end
11
+
12
+ def lookup_address_by_nic(network, nic)
13
+ if network['interfaces'][nic]
14
+ network['interfaces'][nic]['addresses'].each do |ip, params|
15
+ if params['family'] == ('inet')
16
+ return [nic, ip]
17
+ end
18
+ end
19
+ end
20
+ return [nil, nil]
21
+ end
22
+
23
+ def lookup_address_by_ipaddress(network, ip)
24
+ nic = network['interfaces'].find do |nic, nic_info|
25
+ nic_info['addresses'].select {|addr, addr_info| addr_info['family'] == 'inet'}.keys.include?(ip)
26
+ end
27
+ if nic
28
+ return [nic, ip]
29
+ end
30
+ return [nil, nil]
31
+ end
32
+
33
+ provides 'ipaddress'
34
+
35
+ depends 'ipaddress'
36
+ depends 'network'
37
+ depends 'network/interfaces'
38
+ depends 'virtualization/system'
39
+ depends 'etc/passwd'
40
+
41
+ collect_data(:default) do
42
+ # Ohai hint
43
+ unless File.exist?('/etc/chef/ohai_plugins/vagrant.json')
44
+ Ohai::Log.fail('Ohai has not set :ipaddress (Missing vagrant.json)')
45
+ else
46
+ vagrant = read_json('/etc/chef/ohai_plugins/vagrant.json')
47
+
48
+ # requested nit
49
+ nic = vagrant['primary_nic']
50
+ if nic
51
+ nic, addr = lookup_address_by_nic(network, nic)
52
+ elsif vagrant['private_ipv4']
53
+ nic, addr = lookup_address_by_ipaddress(network, vagrant['private_ipv4'])
54
+ else
55
+ nic, addr = nil, nil
56
+ Ohai::Log.info("Neither nic nor private_ipv4 are set, skipping")
57
+ end
58
+ if addr
59
+ Ohai::Log.info("Ohai override :ipaddress to #{addr} from #{nic}")
60
+ ipaddress addr
61
+ end
62
+ end
63
+ end
64
+ 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
+ register_custom_chef_config
13
+ end
14
+
15
+ def call(env)
16
+ @app.call(env)
17
+ end
18
+
19
+ private
20
+ def ohai_custom_config(current_conf)
21
+ tmp = Tempfile.new(["chef-custom-config", ".rb"])
22
+ tmp.puts 'Ohai::config[:plugin_path] << "/etc/chef/ohai_plugins"'
23
+ tmp.write(File.read(current_conf)) if current_conf
24
+ tmp.close
25
+ tmp
26
+ end
27
+
28
+ def register_custom_chef_config
29
+ return unless @machine.config.ohai.enable or @machine.config.ohai.plugins_dir
30
+ chef_provisioners.each do |provisioner|
31
+ if provisioner.config.respond_to? :custom_config_path and not provisioner.config.custom_config_path == Plugin::UNSET_VALUE
32
+ current_custom_config_path = provisioner.config.custom_config_path
33
+ else
34
+ current_custom_config_path = nil
35
+ end
36
+ custom_config = ohai_custom_config(current_custom_config_path)
37
+ provisioner.config.instance_variable_set("@custom_config_path", custom_config.path)
38
+ # retain a reference to prevent tempfile from being auto cleaned up
39
+ provisioner.config.instance_variable_set("@__custom_config_tempfile__", custom_config)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,77 @@
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
+ is_chef_used = chef_provisioners.any?
18
+ @app.call(env)
19
+ return unless @machine.communicate.ready?
20
+
21
+ if is_chef_used && @machine.config.ohai.enable
22
+ @machine.ui.info("Installing Ohai plugin")
23
+ create_ohai_folders
24
+ copy_ohai_plugin
25
+ end
26
+ if is_chef_used && @machine.config.ohai.plugins_dir
27
+ @machine.ui.info("Installing Custom Ohai plugin")
28
+ create_ohai_folders
29
+ copy_ohai_custom_plugins
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def create_ohai_folders
36
+ @machine.communicate.tap do |comm|
37
+ comm.sudo("mkdir -p /etc/chef/ohai_plugins")
38
+ comm.sudo("chown -R #{@machine.ssh_info[:username]} /etc/chef/ohai_plugins")
39
+ end
40
+ end
41
+
42
+ def private_ipv4
43
+ @private_ipv4 ||= @machine.config.vm.networks.find {|network| network.first == :private_network}[1][:ip]
44
+ rescue
45
+ nil
46
+ end
47
+
48
+ def vagrant_info
49
+ info = {}
50
+ info[:box] = @machine.config.vm.box
51
+ info[:primary_nic] = @machine.config.ohai.primary_nic
52
+ info[:private_ipv4] = private_ipv4
53
+ info
54
+ end
55
+
56
+ def copy_ohai_plugin
57
+
58
+ hint_file = Tempfile.new(["vagrant-ohai", ".json"])
59
+ hint_file.write(vagrant_info.to_json)
60
+ hint_file.close
61
+ @machine.communicate.upload(hint_file.path, "/etc/chef/ohai_plugins/vagrant.json")
62
+
63
+ @machine.communicate.upload(OHAI_PLUGIN_PATH, "/etc/chef/ohai_plugins/vagrant.rb")
64
+ end
65
+
66
+ def copy_ohai_custom_plugins
67
+
68
+ files = Dir.entries(@machine.config.ohai.plugins_dir).select { |e| e =~ /^[a-z]+\.rb/ }
69
+ files.each do |file|
70
+ custom_ohai_plugin_path = File.expand_path("#{@machine.config.ohai.plugins_dir}/#{file}", __FILE__)
71
+ @machine.communicate.upload(custom_ohai_plugin_path, "/etc/chef/ohai_plugins/#{file}")
72
+ end
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,48 @@
1
+ module VagrantPlugins
2
+ module Ohai
3
+ class Config < Vagrant.plugin(2, :config)
4
+ attr_accessor :enable
5
+ attr_accessor :primary_nic
6
+ attr_accessor :plugins_dir
7
+
8
+ def initialize
9
+ @enable = UNSET_VALUE
10
+ @primary_nic = UNSET_VALUE
11
+ @plugins_dir = UNSET_VALUE
12
+ end
13
+ def finalize!
14
+ @enable = true if @enable == UNSET_VALUE
15
+ @primary_nic = nil if @primary_nic == UNSET_VALUE
16
+ @plugins_dir = nil if @plugins_dir == UNSET_VALUE
17
+ end
18
+
19
+ def validate(machine)
20
+ case @primary_nic
21
+ when /eth[0-9]+/
22
+ {}
23
+ when nil
24
+ {}
25
+ else
26
+ {"primary_nic" => ["primary_nic must match eth[0-9]+"]}
27
+ end
28
+ case @enable
29
+ when TrueClass, FalseClass
30
+ {}
31
+ else
32
+ {"enable" => ["enable must be true or false"] }
33
+ end
34
+ case @plugins_dir
35
+ when nil
36
+ {}
37
+ else
38
+ if !File.directory?(@plugins_dir.to_s) or @plugins_dir.to_s !~ /^\//
39
+ {"plugins_dir" => ["plugins_dir must be an absolute path to a folder"]}
40
+ else
41
+ {}
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ module VagrantPlugins
2
+ module Ohai
3
+ #
4
+ module Helpers
5
+ def chef_provisioners
6
+ @machine.config.vm.provisioners.find_all do |provisioner|
7
+ provisioner_name = provisioner.respond_to?('type') ? provisioner.type : provisioner.name
8
+ [:shell, :chef_client, :chef_solo, :chef_zero, :chef_apply].include? provisioner_name
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Ohai
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ require "vagrant-ohai/version"
2
+ require "vagrant/plugin"
3
+
4
+ raise RuntimeError, "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
+ action_hook(:install_ohai_plugin, Plugin::ALL_ACTIONS) 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
+ config(:ohai) do
23
+ require_relative "config"
24
+ Config
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Ohai
3
+ VERSION = "0.1.14"
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-ohai2"
8
+ spec.version = VagrantPlugins::Ohai::VERSION
9
+ spec.authors = ["Jeremy Miller"]
10
+ spec.email = ["jmiller3346@gmail.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-ohai2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.14
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Miller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-26 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
+ - jmiller3346@gmail.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.6.13
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Vagrant plugin which installs an Ohai plugn to properly detect private ipaddress
88
+ test_files: []