Last active
May 13, 2023 15:06
-
-
Save sneal/9242343 to your computer and use it in GitHub Desktop.
Gem install from Vagrantfile
This file contains hidden or 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
require "rubygems" | |
# Install the Chef gem into the private Vagrant gem repo | |
CHEF_VERSION = '11.8.2' | |
def with_vagrant_gem_path | |
@old_gem_path = ENV["GEM_PATH"] | |
@old_gem_home = ENV["GEM_HOME"] | |
Gem.paths = ENV["GEM_PATH"] = ENV["GEM_HOME"] = "#{ENV['HOME']}/.vagrant.d/gems" | |
return yield | |
ensure | |
ENV["GEM_PATH"] = @old_gem_path | |
ENV["GEM_HOME"] = @old_gem_home | |
Gem.paths = ENV | |
end | |
begin | |
Gem::Specification.find_by_name('chef', CHEF_VERSION) | |
rescue Gem::LoadError | |
require "rubygems/dependency_installer" | |
with_vagrant_gem_path do | |
installer = Gem::DependencyInstaller.new(:document => [], :prerelease => false) | |
installer.install('chef', CHEF_VERSION) | |
end | |
end | |
# This pulls in the knife.rb config | |
require 'chef' | |
Chef::Config.from_file(File.join(ENV['HOME'], '.chef', 'knife.rb')) | |
Vagrant.configure("2") do |config| | |
config.vm.provision :chef_client do |chef| | |
chef.chef_server_url = Chef::Config[:chef_server_url] | |
chef.log_level = Chef::Config[:log_level] | |
chef.validation_key_path = Chef::Config[:validation_key] | |
chef.validation_client_name = Chef::Config[:validation_client_name] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment