Add config option omnibus_url for chef provisioners
This option is useful for internal setups, where own customized omnibus installation script is used (e.g. to get chef from a mirror)
This commit is contained in:
parent
e697f2f9a5
commit
875c2edc62
|
@ -5,11 +5,11 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
module Debian
|
module Debian
|
||||||
module ChefInstall
|
module ChefInstall
|
||||||
def self.chef_install(machine, project, version, channel, options = {})
|
def self.chef_install(machine, project, version, channel, omnibus_url, options = {})
|
||||||
machine.communicate.sudo("apt-get update -y -qq")
|
machine.communicate.sudo("apt-get update -y -qq")
|
||||||
machine.communicate.sudo("apt-get install -y -qq curl")
|
machine.communicate.sudo("apt-get install -y -qq curl")
|
||||||
|
|
||||||
command = Omnibus.sh_command(project, version, channel, options)
|
command = Omnibus.sh_command(project, version, channel, omnibus_url, options)
|
||||||
machine.communicate.sudo(command)
|
machine.communicate.sudo(command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,10 +5,10 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
module FreeBSD
|
module FreeBSD
|
||||||
module ChefInstall
|
module ChefInstall
|
||||||
def self.chef_install(machine, project, version, channel, options = {})
|
def self.chef_install(machine, project, version, channel, omnibus_url, options = {})
|
||||||
machine.communicate.sudo("pkg install -y -qq curl bash")
|
machine.communicate.sudo("pkg install -y -qq curl bash")
|
||||||
|
|
||||||
command = Omnibus.sh_command(project, version, channel, options)
|
command = Omnibus.sh_command(project, version, channel, omnibus_url, options)
|
||||||
machine.communicate.sudo(command)
|
machine.communicate.sudo(command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,12 +5,12 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
module OmniOS
|
module OmniOS
|
||||||
module ChefInstall
|
module ChefInstall
|
||||||
def self.chef_install(machine, project, version, channel, options = {})
|
def self.chef_install(machine, project, version, channel, omnibus_url, options = {})
|
||||||
su = machine.config.solaris.suexec_cmd
|
su = machine.config.solaris.suexec_cmd
|
||||||
|
|
||||||
machine.communicate.execute("#{su} pkg list --no-refresh web/curl > /dev/null 2>&1 || pkg install -q --accept web/curl")
|
machine.communicate.execute("#{su} pkg list --no-refresh web/curl > /dev/null 2>&1 || pkg install -q --accept web/curl")
|
||||||
|
|
||||||
command = Omnibus.sh_command(project, version, channel, options)
|
command = Omnibus.sh_command(project, version, channel, omnibus_url, options)
|
||||||
machine.communicate.execute("#{su} #{command}")
|
machine.communicate.execute("#{su} #{command}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
module Redhat
|
module Redhat
|
||||||
module ChefInstall
|
module ChefInstall
|
||||||
def self.chef_install(machine, project, version, channel, options = {})
|
def self.chef_install(machine, project, version, channel, omnibus_url, options = {})
|
||||||
machine.communicate.sudo <<-EOH.gsub(/^ {14}/, '')
|
machine.communicate.sudo <<-EOH.gsub(/^ {14}/, '')
|
||||||
if command -v dnf; then
|
if command -v dnf; then
|
||||||
dnf -y install curl
|
dnf -y install curl
|
||||||
|
@ -14,7 +14,7 @@ module VagrantPlugins
|
||||||
fi
|
fi
|
||||||
EOH
|
EOH
|
||||||
|
|
||||||
command = Omnibus.sh_command(project, version, channel, options)
|
command = Omnibus.sh_command(project, version, channel, omnibus_url, options)
|
||||||
machine.communicate.sudo(command)
|
machine.communicate.sudo(command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,13 +5,13 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
module Suse
|
module Suse
|
||||||
module ChefInstall
|
module ChefInstall
|
||||||
def self.chef_install(machine, project, version, channel, options = {})
|
def self.chef_install(machine, project, version, channel, omnibus_url, options = {})
|
||||||
unless curl?(machine)
|
unless curl?(machine)
|
||||||
machine.communicate.sudo("zypper -n -q update")
|
machine.communicate.sudo("zypper -n -q update")
|
||||||
machine.communicate.sudo("zypper -n -q install curl")
|
machine.communicate.sudo("zypper -n -q install curl")
|
||||||
end
|
end
|
||||||
|
|
||||||
command = Omnibus.sh_command(project, version, channel, options)
|
command = Omnibus.sh_command(project, version, channel, omnibus_url, options)
|
||||||
machine.communicate.sudo(command)
|
machine.communicate.sudo(command)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ module VagrantPlugins
|
||||||
module Cap
|
module Cap
|
||||||
module Windows
|
module Windows
|
||||||
module ChefInstall
|
module ChefInstall
|
||||||
def self.chef_install(machine, project, version, channel, options = {})
|
def self.chef_install(machine, project, version, channel, omnibus_url, options = {})
|
||||||
command = Omnibus.ps_command(project, version, channel, options)
|
command = Omnibus.ps_command(project, version, channel, omnibus_url, options)
|
||||||
machine.communicate.sudo(command)
|
machine.communicate.sudo(command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,6 +56,21 @@ module VagrantPlugins
|
||||||
# @return [String]
|
# @return [String]
|
||||||
attr_accessor :version
|
attr_accessor :version
|
||||||
|
|
||||||
|
# Location of Omnibus installation scripts.
|
||||||
|
# This URL specifies the location of install.sh/install.ps1 for
|
||||||
|
# Linux/Unix and Windows respectively.
|
||||||
|
#
|
||||||
|
# It defaults to https://omnitruck.chef.io/. The full URL is then:
|
||||||
|
# - Linux/Unix: https://omnitruck.chef.io/install.sh
|
||||||
|
# - Windows: https://omnitruck.chef.io/install.ps1
|
||||||
|
#
|
||||||
|
# If you want to have https://example.com/install.sh as Omnibus script
|
||||||
|
# for your Linux/Unix installations, you should set this option to
|
||||||
|
# https://example.com
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
attr_accessor :omnibus_url
|
||||||
|
|
||||||
# The path where the Chef installer will be downloaded to. Only valid if
|
# 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
|
# install is true or "force". It defaults to nil, which means that the
|
||||||
# omnibus installer will choose the destination and you have no control
|
# omnibus installer will choose the destination and you have no control
|
||||||
|
@ -74,6 +89,7 @@ module VagrantPlugins
|
||||||
@log_level = UNSET_VALUE
|
@log_level = UNSET_VALUE
|
||||||
@channel = UNSET_VALUE
|
@channel = UNSET_VALUE
|
||||||
@version = UNSET_VALUE
|
@version = UNSET_VALUE
|
||||||
|
@omnibus_url = UNSET_VALUE
|
||||||
@installer_download_path = UNSET_VALUE
|
@installer_download_path = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -85,6 +101,7 @@ module VagrantPlugins
|
||||||
@log_level = :info if @log_level == UNSET_VALUE
|
@log_level = :info if @log_level == UNSET_VALUE
|
||||||
@channel = "stable" if @channel == UNSET_VALUE
|
@channel = "stable" if @channel == UNSET_VALUE
|
||||||
@version = :latest if @version == UNSET_VALUE
|
@version = :latest if @version == UNSET_VALUE
|
||||||
|
@omnibus_url = 'https://omnitruck.chef.io' if @omnibus_url == UNSET_VALUE
|
||||||
@installer_download_path = nil if @installer_download_path == 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
|
# Make sure the install is a symbol if it's not a boolean
|
||||||
|
|
|
@ -2,12 +2,13 @@ module VagrantPlugins
|
||||||
module Chef
|
module Chef
|
||||||
class Installer
|
class Installer
|
||||||
def initialize(machine, options = {})
|
def initialize(machine, options = {})
|
||||||
@machine = machine
|
@machine = machine
|
||||||
@product = options.fetch(:product)
|
@product = options.fetch(:product)
|
||||||
@channel = options.fetch(:channel)
|
@channel = options.fetch(:channel)
|
||||||
@version = options.fetch(:version)
|
@version = options.fetch(:version)
|
||||||
@force = options.fetch(:force)
|
@force = options.fetch(:force)
|
||||||
@options = options.dup
|
@omnibus_url = options.fetch(:omnibus_url)
|
||||||
|
@options = options.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
# This handles verifying the Chef installation, installing it if it was
|
# This handles verifying the Chef installation, installing it if it was
|
||||||
|
@ -29,7 +30,7 @@ module VagrantPlugins
|
||||||
|
|
||||||
@machine.ui.detail(I18n.t("vagrant.chef_installing",
|
@machine.ui.detail(I18n.t("vagrant.chef_installing",
|
||||||
version: @version.to_s))
|
version: @version.to_s))
|
||||||
@machine.guest.capability(:chef_install, @product, @version, @channel, @options)
|
@machine.guest.capability(:chef_install, @product, @version, @channel, @omnibus_url, @options)
|
||||||
|
|
||||||
if !@machine.guest.capability(:chef_installed, @product, @version)
|
if !@machine.guest.capability(:chef_installed, @product, @version)
|
||||||
raise Provisioner::Base::ChefError, :install_failed
|
raise Provisioner::Base::ChefError, :install_failed
|
||||||
|
|
|
@ -5,10 +5,8 @@ module VagrantPlugins
|
||||||
# https://docs.chef.io/install_omnibus.html
|
# https://docs.chef.io/install_omnibus.html
|
||||||
#
|
#
|
||||||
module Omnibus
|
module Omnibus
|
||||||
OMNITRUCK = "https://omnitruck.chef.io".freeze
|
def sh_command(project, version, channel, omnibus_url, options = {})
|
||||||
|
command = "curl -sL #{omnibus_url}/install.sh | bash"
|
||||||
def sh_command(project, version, channel, options = {})
|
|
||||||
command = "curl -sL #{OMNITRUCK}/install.sh | bash"
|
|
||||||
command << " -s -- -P \"#{project}\" -c \"#{channel}\""
|
command << " -s -- -P \"#{project}\" -c \"#{channel}\""
|
||||||
|
|
||||||
if version != :latest
|
if version != :latest
|
||||||
|
@ -23,8 +21,8 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
module_function :sh_command
|
module_function :sh_command
|
||||||
|
|
||||||
def ps_command(project, version, channel, options = {})
|
def ps_command(project, version, channel, omnibus_url, options = {})
|
||||||
command = ". { iwr -useb #{OMNITRUCK}/install.ps1 } | iex; install"
|
command = ". { iwr -useb #{omnibus_url}/install.ps1 } | iex; install"
|
||||||
command << " -project '#{project}' -channel '#{channel}'"
|
command << " -project '#{project}' -channel '#{channel}'"
|
||||||
|
|
||||||
if version != :latest
|
if version != :latest
|
||||||
|
|
|
@ -58,6 +58,7 @@ module VagrantPlugins
|
||||||
product: config.product,
|
product: config.product,
|
||||||
channel: config.channel,
|
channel: config.channel,
|
||||||
version: config.version,
|
version: config.version,
|
||||||
|
omnibus_url: config.omnibus_url,
|
||||||
force: config.install == :force,
|
force: config.install == :force,
|
||||||
download_path: config.installer_download_path
|
download_path: config.installer_download_path
|
||||||
)
|
)
|
||||||
|
|
|
@ -82,4 +82,17 @@ describe VagrantPlugins::Chef::Config::Base do
|
||||||
expect(subject.installer_download_path).to be(nil)
|
expect(subject.installer_download_path).to be(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#omnibus_url" do
|
||||||
|
it "defaults to https://omnitruck.chef.io" do
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.omnibus_url).to eq("https://omnitruck.chef.io")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "makes use of the configured url" do
|
||||||
|
subject.omnibus_url = "https://omnitruck.example.com"
|
||||||
|
subject.finalize!
|
||||||
|
expect(subject.omnibus_url).to eq("https://omnitruck.example.com")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,22 +5,27 @@ require Vagrant.source_root.join("plugins/provisioners/chef/omnibus")
|
||||||
describe VagrantPlugins::Chef::Omnibus do
|
describe VagrantPlugins::Chef::Omnibus do
|
||||||
describe "#sh_command" do
|
describe "#sh_command" do
|
||||||
it "includes the project name" do
|
it "includes the project name" do
|
||||||
command = described_class.sh_command("chef", nil, "stable")
|
command = described_class.sh_command("chef", nil, "stable", "https://omnitruck.chef.io")
|
||||||
expect(command).to include %|-P "chef"|
|
expect(command).to include %|-P "chef"|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes the channel" do
|
it "includes the channel" do
|
||||||
command = described_class.sh_command("chef", nil, "stable")
|
command = described_class.sh_command("chef", nil, "stable", "https://omnitruck.chef.io")
|
||||||
expect(command).to include %|-c "stable"|
|
expect(command).to include %|-c "stable"|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes the version" do
|
it "includes the version" do
|
||||||
command = described_class.sh_command("chef", "1.2.3", "stable")
|
command = described_class.sh_command("chef", "1.2.3", "stable", "https://omnitruck.chef.io")
|
||||||
expect(command).to include %|-v "1.2.3"|
|
expect(command).to include %|-v "1.2.3"|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "includes the Omnibus installation URL" do
|
||||||
|
command = described_class.sh_command("chef", "1.2.3", "stable", "https://omnitruck.chef.io")
|
||||||
|
expect(command).to include %|https://omnitruck.chef.io/install.sh|
|
||||||
|
end
|
||||||
|
|
||||||
it "includes the download path" do
|
it "includes the download path" do
|
||||||
command = described_class.sh_command("chef", "1.2.3", "stable",
|
command = described_class.sh_command("chef", "1.2.3", "stable", "https://omnitruck.chef.io",
|
||||||
download_path: "/some/path",
|
download_path: "/some/path",
|
||||||
)
|
)
|
||||||
expect(command).to include %|-d "/some/path"|
|
expect(command).to include %|-d "/some/path"|
|
||||||
|
@ -29,18 +34,23 @@ describe VagrantPlugins::Chef::Omnibus do
|
||||||
|
|
||||||
describe "#ps_command" do
|
describe "#ps_command" do
|
||||||
it "includes the project name" do
|
it "includes the project name" do
|
||||||
command = described_class.ps_command("chef", nil, "stable")
|
command = described_class.ps_command("chef", nil, "stable", "https://omnitruck.chef.io")
|
||||||
expect(command).to include %|-project 'chef'|
|
expect(command).to include %|-project 'chef'|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes the channel" do
|
it "includes the channel" do
|
||||||
command = described_class.ps_command("chef", nil, "stable")
|
command = described_class.ps_command("chef", nil, "stable", "https://omnitruck.chef.io")
|
||||||
expect(command).to include %|-channel 'stable'|
|
expect(command).to include %|-channel 'stable'|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "includes the version" do
|
it "includes the version" do
|
||||||
command = described_class.ps_command("chef", "1.2.3", "stable")
|
command = described_class.ps_command("chef", "1.2.3", "stable", "https://omnitruck.chef.io")
|
||||||
expect(command).to include %|-version '1.2.3'|
|
expect(command).to include %|-version '1.2.3'|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "includes the Omnibus installation URL" do
|
||||||
|
command = described_class.ps_command("chef", "1.2.3", "stable", "https://omnitruck.chef.io")
|
||||||
|
expect(command).to include %|https://omnitruck.chef.io/install.ps1|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,12 +59,22 @@ understand their purpose.
|
||||||
requested version. If they match, no action is taken. If they do not match,
|
requested version. If they match, no action is taken. If they do not match,
|
||||||
the value specified in this attribute will be installed in favor of the
|
the value specified in this attribute will be installed in favor of the
|
||||||
existing version (a message will be displayed).
|
existing version (a message will be displayed).
|
||||||
|
|
||||||
You can also specify "latest" (default), which will install the latest
|
You can also specify "latest" (default), which will install the latest
|
||||||
version of Chef on the system. In this case, Chef will use whatever
|
version of Chef on the system. In this case, Chef will use whatever
|
||||||
version is on the system. To force the newest version of Chef to be
|
version is on the system. To force the newest version of Chef to be
|
||||||
installed on every provision, set the [`install`](#install) option to "force".
|
installed on every provision, set the [`install`](#install) option to "force".
|
||||||
|
|
||||||
|
- `omnibus_url` (string) - Location of Omnibus installation scripts.
|
||||||
|
This URL specifies the location of install.sh/install.ps1 for
|
||||||
|
Linux/Unix and Windows respectively.
|
||||||
|
It defaults to https://omnitruck.chef.io. The full URL is in this case:
|
||||||
|
|
||||||
|
- Linux/Unix: https://omnitruck.chef.io/install.sh
|
||||||
|
- Windows: https://omnitruck.chef.io/install.ps1
|
||||||
|
|
||||||
|
If you want to have https://example.com/install.sh as Omnibus script
|
||||||
|
for your Linux/Unix installations, you should set this option to
|
||||||
|
https://example.com
|
||||||
|
|
||||||
## Runner Chef Provisioners
|
## Runner Chef Provisioners
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue