Merge pull request #5002 from tknerr/chef-installer-download-path
Add `installer_download_path` config option to chef provisioners
This commit is contained in:
commit
9fa2ea4e31
|
@ -5,11 +5,11 @@ module VagrantPlugins
|
|||
module Cap
|
||||
module Debian
|
||||
module ChefInstall
|
||||
def self.chef_install(machine, version, prerelease)
|
||||
def self.chef_install(machine, version, prerelease, download_path)
|
||||
machine.communicate.sudo("apt-get update -y -qq")
|
||||
machine.communicate.sudo("apt-get install -y -qq curl")
|
||||
|
||||
command = Omnibus.build_command(version, prerelease)
|
||||
command = Omnibus.build_command(version, prerelease, download_path)
|
||||
machine.communicate.sudo(command)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,10 +5,10 @@ module VagrantPlugins
|
|||
module Cap
|
||||
module Redhat
|
||||
module ChefInstall
|
||||
def self.chef_install(machine, version, prerelease)
|
||||
def self.chef_install(machine, version, prerelease, download_path)
|
||||
machine.communicate.sudo("yum install -y -q curl")
|
||||
|
||||
command = Omnibus.build_command(version, prerelease)
|
||||
command = Omnibus.build_command(version, prerelease, download_path)
|
||||
machine.communicate.sudo(command)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,6 +48,14 @@ module VagrantPlugins
|
|||
# @return [String]
|
||||
attr_accessor :version
|
||||
|
||||
# The path where the Chef installer will be downloaded to. Only valid if
|
||||
# install is true or "force". It defaults to nil, which means that the
|
||||
# omnibus installer will choose the destination and you have no control
|
||||
# over it.
|
||||
#
|
||||
# @return [String]
|
||||
attr_accessor :installer_download_path
|
||||
|
||||
def initialize
|
||||
super
|
||||
|
||||
|
@ -57,6 +65,7 @@ module VagrantPlugins
|
|||
@log_level = UNSET_VALUE
|
||||
@prerelease = UNSET_VALUE
|
||||
@version = UNSET_VALUE
|
||||
@installer_download_path = UNSET_VALUE
|
||||
end
|
||||
|
||||
def finalize!
|
||||
|
@ -66,6 +75,7 @@ module VagrantPlugins
|
|||
@log_level = :info if @log_level == UNSET_VALUE
|
||||
@prerelease = false if @prerelease == UNSET_VALUE
|
||||
@version = :latest if @version == UNSET_VALUE
|
||||
@installer_download_path = nil if @installer_download_path == UNSET_VALUE
|
||||
|
||||
# Make sure the install is a symbol if it's not a boolean
|
||||
if @install.respond_to?(:to_sym)
|
||||
|
|
|
@ -6,6 +6,7 @@ module VagrantPlugins
|
|||
@version = options.fetch(:version, :latest)
|
||||
@prerelease = options.fetch(:prerelease, :latest)
|
||||
@force = options.fetch(:force, false)
|
||||
@download_path = options.fetch(:download_path, nil)
|
||||
end
|
||||
|
||||
# This handles verifying the Chef installation, installing it if it was
|
||||
|
@ -27,7 +28,7 @@ module VagrantPlugins
|
|||
|
||||
@machine.ui.detail(I18n.t("vagrant.chef_installing",
|
||||
version: @version.to_s))
|
||||
@machine.guest.capability(:chef_install, @version, @prerelease)
|
||||
@machine.guest.capability(:chef_install, @version, @prerelease, @download_path)
|
||||
|
||||
if !@machine.guest.capability(:chef_installed, @version)
|
||||
raise Provisioner::Base::ChefError, :install_failed
|
||||
|
|
|
@ -5,10 +5,10 @@ module VagrantPlugins
|
|||
|
||||
# Read more about the Omnibus installer here:
|
||||
# https://docs.getchef.com/install_omnibus.html
|
||||
def build_command(version, prerelease = false)
|
||||
def build_command(version, prerelease = false, download_path = nil)
|
||||
command = "curl -sL #{OMNITRUCK} | sudo bash"
|
||||
|
||||
if prerelease || version != :latest
|
||||
if prerelease || version != :latest || download_path != nil
|
||||
command << " -s --"
|
||||
end
|
||||
|
||||
|
@ -20,6 +20,10 @@ module VagrantPlugins
|
|||
command << " -v \"#{version}\""
|
||||
end
|
||||
|
||||
if download_path
|
||||
command << " -d \"#{download_path}\""
|
||||
end
|
||||
|
||||
command
|
||||
end
|
||||
module_function :build_command
|
||||
|
|
|
@ -29,6 +29,7 @@ module VagrantPlugins
|
|||
force: config.install == :force,
|
||||
version: config.version,
|
||||
prerelease: config.prerelease,
|
||||
download_path: config.installer_download_path
|
||||
)
|
||||
installer.ensure_installed
|
||||
end
|
||||
|
|
|
@ -68,4 +68,11 @@ describe VagrantPlugins::Chef::Config::Base do
|
|||
expect(subject.version).to eq(:latest)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#installer_download_path" do
|
||||
it "defaults to nil" do
|
||||
subject.finalize!
|
||||
expect(subject.installer_download_path).to be(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,8 +7,9 @@ describe VagrantPlugins::Chef::Omnibus, :focus do
|
|||
|
||||
let(:version) { :latest }
|
||||
let(:prerelease) { false }
|
||||
let(:download_path) { nil }
|
||||
|
||||
let(:build_command) { described_class.build_command(version, prerelease) }
|
||||
let(:build_command) { described_class.build_command(version, prerelease, download_path) }
|
||||
|
||||
context "when prerelease is given" do
|
||||
let(:prerelease) { true }
|
||||
|
@ -18,6 +19,14 @@ describe VagrantPlugins::Chef::Omnibus, :focus do
|
|||
end
|
||||
end
|
||||
|
||||
context "when download_path is given" do
|
||||
let(:download_path) { '/tmp/path/to/omnibuses' }
|
||||
|
||||
it "returns the correct command" do
|
||||
expect(build_command).to eq("#{prefix} | sudo bash -s -- -d \"/tmp/path/to/omnibuses\"")
|
||||
end
|
||||
end
|
||||
|
||||
context "when version is :latest" do
|
||||
let(:version) { :latest }
|
||||
|
||||
|
@ -34,12 +43,13 @@ describe VagrantPlugins::Chef::Omnibus, :focus do
|
|||
end
|
||||
end
|
||||
|
||||
context "when prerelease and version are given" do
|
||||
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\"")
|
||||
expect(build_command).to eq("#{prefix} | sudo bash -s -- -p -v \"1.2.3\" -d \"/some/path\"")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue