Allow Chef to install on Windows

This commit is contained in:
Seth Vargo 2015-11-19 15:01:09 -08:00
parent a90e6cfe4c
commit c30467a6f9
4 changed files with 89 additions and 71 deletions

View File

@ -0,0 +1,16 @@
require_relative "../../omnibus"
module VagrantPlugins
module Chef
module Cap
module Windows
module ChefInstall
def self.chef_install(machine, project, version, channel, options = {})
command = Omnibus.ps_command(project, version, channel, options)
machine.communicate.sudo(command)
end
end
end
end
end
end

View File

@ -1,32 +1,39 @@
module VagrantPlugins module VagrantPlugins
module Chef module Chef
module Omnibus
OMNITRUCK = "https://www.chef.io/chef/install.sh".freeze
# Read more about the Omnibus installer here: # Read more about the Omnibus installer here:
# https://docs.getchef.com/install_omnibus.html #
def build_command(version, prerelease = false, download_path = nil) # https://docs.chef.io/install_omnibus.html
command = "curl -sL #{OMNITRUCK} | sudo bash" #
module Omnibus
OMNITRUCK = "https://omnitruck.chef.io".freeze
if prerelease || version != :latest || download_path != nil def sh_command(project, version, channel, options = {})
command << " -s --" command = "curl -sL #{OMNITRUCK}/install.sh | sudo bash"
end command << " -s -- -P \"#{project}\" -c \"#{channel}\""
if prerelease
command << " -p"
end
if version != :latest if version != :latest
command << " -v \"#{version}\"" command << " -v \"#{version}\""
end end
if download_path if options[:download_path]
command << " -d \"#{download_path}\"" command << " -d \"#{options[:download_path]}\""
end end
command command
end end
module_function :build_command module_function :sh_command
def ps_command(project, version, channel, options = {})
command = ". { iwr -useb #{OMNITRUCK}/install.ps1 } | iex; install"
command << " -project '#{project}' -channel '#{channel}'"
if version != :latest
command << " -version '#{version}'"
end
command
end
module_function :ps_command
end end
end end
end end

View File

@ -53,29 +53,14 @@ module VagrantPlugins
Provisioner::ChefZero Provisioner::ChefZero
end end
guest_capability(:linux, :chef_installed) do
require_relative "cap/linux/chef_installed"
Cap::Linux::ChefInstalled
end
guest_capability(:windows, :chef_installed) do
require_relative "cap/windows/chef_installed"
Cap::Windows::ChefInstalled
end
guest_capability(:debian, :chef_install) do guest_capability(:debian, :chef_install) do
require_relative "cap/debian/chef_install" require_relative "cap/debian/chef_install"
Cap::Debian::ChefInstall Cap::Debian::ChefInstall
end end
guest_capability(:redhat, :chef_install) do guest_capability(:linux, :chef_installed) do
require_relative "cap/redhat/chef_install" require_relative "cap/linux/chef_installed"
Cap::Redhat::ChefInstall Cap::Linux::ChefInstalled
end
guest_capability(:omnios, :chef_installed) do
require_relative "cap/omnios/chef_installed"
Cap::OmniOS::ChefInstalled
end end
guest_capability(:omnios, :chef_install) do guest_capability(:omnios, :chef_install) do
@ -83,6 +68,25 @@ module VagrantPlugins
Cap::OmniOS::ChefInstall Cap::OmniOS::ChefInstall
end end
guest_capability(:omnios, :chef_installed) do
require_relative "cap/omnios/chef_installed"
Cap::OmniOS::ChefInstalled
end
guest_capability(:redhat, :chef_install) do
require_relative "cap/redhat/chef_install"
Cap::Redhat::ChefInstall
end
guest_capability(:windows, :chef_install) do
require_relative "cap/windows/chef_install"
Cap::Windows::ChefInstall
end
guest_capability(:windows, :chef_installed) do
require_relative "cap/windows/chef_installed"
Cap::Windows::ChefInstalled
end
end end
end end
end end

View File

@ -3,53 +3,44 @@ require_relative "../../../base"
require Vagrant.source_root.join("plugins/provisioners/chef/omnibus") require Vagrant.source_root.join("plugins/provisioners/chef/omnibus")
describe VagrantPlugins::Chef::Omnibus do describe VagrantPlugins::Chef::Omnibus do
let(:prefix) { "curl -sL #{described_class.const_get(:OMNITRUCK)}" } describe "#sh_command" do
it "includes the project name" do
command = described_class.sh_command("chef", nil, "stable")
expect(command).to include %|-P "chef"|
end
let(:version) { :latest } it "includes the channel" do
let(:prerelease) { false } command = described_class.sh_command("chef", nil, "stable")
let(:download_path) { nil } expect(command).to include %|-c "stable"|
end
let(:build_command) { described_class.build_command(version, prerelease, download_path) } it "includes the version" do
command = described_class.sh_command("chef", "1.2.3", "stable")
expect(command).to include %|-v "1.2.3"|
end
context "when prerelease is given" do it "includes the download path" do
let(:prerelease) { true } command = described_class.sh_command("chef", "1.2.3", "stable",
download_path: "/some/path",
it "returns the correct command" do )
expect(build_command).to eq("#{prefix} | sudo bash -s -- -p") expect(command).to include %|-d "/some/path"|
end end
end end
context "when download_path is given" do describe "#ps_command" do
let(:download_path) { '/tmp/path/to/omnibuses' } it "includes the project name" do
command = described_class.ps_command("chef", nil, "stable")
it "returns the correct command" do expect(command).to include %|-project 'chef'|
expect(build_command).to eq("#{prefix} | sudo bash -s -- -d \"/tmp/path/to/omnibuses\"")
end
end end
context "when version is :latest" do it "includes the channel" do
let(:version) { :latest } command = described_class.ps_command("chef", nil, "stable")
expect(command).to include %|-channel 'stable'|
it "returns the correct command" do
expect(build_command).to eq("#{prefix} | sudo bash")
end
end end
context "when version is a string" do it "includes the version" do
let(:version) { "1.2.3" } command = described_class.ps_command("chef", "1.2.3", "stable")
expect(command).to include %|-version '1.2.3'|
it "returns the correct command" do
expect(build_command).to eq("#{prefix} | sudo bash -s -- -v \"1.2.3\"")
end
end
context "when prerelease and version and download_path are given" do
let(:version) { "1.2.3" }
let(:prerelease) { true }
let(:download_path) { "/some/path" }
it "returns the correct command" do
expect(build_command).to eq("#{prefix} | sudo bash -s -- -p -v \"1.2.3\" -d \"/some/path\"")
end end
end end
end end