2015-11-23 23:14:32 +00:00
|
|
|
require "vagrant/util/presence"
|
|
|
|
|
2013-01-14 00:41:32 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Chef
|
|
|
|
module Config
|
|
|
|
class Base < Vagrant.plugin("2", :config)
|
2015-11-23 23:14:32 +00:00
|
|
|
include Vagrant::Util::Presence
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# The path to Chef's bin/ directory.
|
|
|
|
# @return [String]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :binary_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# Arbitrary environment variables to set before running the Chef
|
|
|
|
# provisioner command.
|
|
|
|
# @return [String]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :binary_env
|
2014-10-31 18:22:09 +00:00
|
|
|
|
2015-11-19 22:57:01 +00:00
|
|
|
# The name of the Chef project to install. This is "chef" for the Chef
|
|
|
|
# Client or "chefdk" for the Chef Development Kit. Other product names
|
|
|
|
# may be available as well.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :product
|
|
|
|
|
2014-10-31 18:22:24 +00:00
|
|
|
# Install Chef on the system if it does not exist. Default is true.
|
|
|
|
# This is a trinary attribute (it can have three values):
|
|
|
|
#
|
|
|
|
# - true (bool) install Chef
|
|
|
|
# - false (bool) do not install Chef
|
|
|
|
# - "force" (string) install Chef, even if it is already installed at
|
|
|
|
# the proper version
|
|
|
|
#
|
|
|
|
# @return [true, false, String]
|
|
|
|
attr_accessor :install
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# The Chef log level. See the Chef docs for acceptable values.
|
|
|
|
# @return [String, Symbol]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :log_level
|
2014-10-31 18:22:09 +00:00
|
|
|
|
2015-11-19 22:57:01 +00:00
|
|
|
# The channel from which to download Chef. Currently known values are
|
|
|
|
# "current" and "stable", but more may be added in the future. The
|
2016-02-08 15:48:22 +00:00
|
|
|
# default is "stable".
|
2015-11-19 22:57:01 +00:00
|
|
|
# @return [String]
|
|
|
|
attr_accessor :channel
|
2014-10-31 20:06:05 +00:00
|
|
|
|
2014-10-31 18:22:24 +00:00
|
|
|
# The version of Chef to install. If Chef is already installed on the
|
|
|
|
# system, the installed version is compared with the requested version.
|
|
|
|
# If they match, no action is taken. If they do not match, version of
|
|
|
|
# the value specified in this attribute will be installed over top of
|
|
|
|
# the existing version (a warning will be displayed).
|
|
|
|
#
|
|
|
|
# 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 is on the system. To force the newest version of Chef to be
|
|
|
|
# installed on every provision, set the {#install} option to "force".
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :version
|
2013-04-15 19:08:08 +00:00
|
|
|
|
2017-06-14 10:34:52 +00:00
|
|
|
# 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
|
|
|
|
|
2015-01-06 18:31:13 +00:00
|
|
|
# The path where the Chef installer will be downloaded to. Only valid if
|
2014-12-16 21:40:19 +00:00
|
|
|
# install is true or "force". It defaults to nil, which means that the
|
2015-01-06 18:31:13 +00:00
|
|
|
# omnibus installer will choose the destination and you have no control
|
|
|
|
# over it.
|
|
|
|
#
|
2014-12-16 21:40:19 +00:00
|
|
|
# @return [String]
|
|
|
|
attr_accessor :installer_download_path
|
|
|
|
|
2013-04-15 19:08:08 +00:00
|
|
|
def initialize
|
|
|
|
super
|
2013-01-14 00:41:32 +00:00
|
|
|
|
2014-10-31 20:06:05 +00:00
|
|
|
@binary_path = UNSET_VALUE
|
|
|
|
@binary_env = UNSET_VALUE
|
2015-11-19 22:57:01 +00:00
|
|
|
@product = UNSET_VALUE
|
2014-10-31 20:06:05 +00:00
|
|
|
@install = UNSET_VALUE
|
|
|
|
@log_level = UNSET_VALUE
|
2015-11-19 22:57:01 +00:00
|
|
|
@channel = UNSET_VALUE
|
2014-10-31 20:06:05 +00:00
|
|
|
@version = UNSET_VALUE
|
2017-06-14 10:34:52 +00:00
|
|
|
@omnibus_url = UNSET_VALUE
|
2014-12-16 21:40:19 +00:00
|
|
|
@installer_download_path = UNSET_VALUE
|
2014-01-17 02:03:38 +00:00
|
|
|
end
|
|
|
|
|
2013-04-15 19:08:08 +00:00
|
|
|
def finalize!
|
2015-11-19 22:57:01 +00:00
|
|
|
@binary_path = nil if @binary_path == UNSET_VALUE
|
|
|
|
@binary_env = nil if @binary_env == UNSET_VALUE
|
|
|
|
@product = "chef" if @product == UNSET_VALUE
|
|
|
|
@install = true if @install == UNSET_VALUE
|
|
|
|
@log_level = :info if @log_level == UNSET_VALUE
|
2016-02-08 15:48:22 +00:00
|
|
|
@channel = "stable" if @channel == UNSET_VALUE
|
2015-11-19 22:57:01 +00:00
|
|
|
@version = :latest if @version == UNSET_VALUE
|
2017-06-14 10:34:52 +00:00
|
|
|
@omnibus_url = 'https://omnitruck.chef.io' if @omnibus_url == UNSET_VALUE
|
2014-12-16 21:40:19 +00:00
|
|
|
@installer_download_path = nil if @installer_download_path == UNSET_VALUE
|
2014-10-31 20:06:05 +00:00
|
|
|
|
|
|
|
# Make sure the install is a symbol if it's not a boolean
|
|
|
|
if @install.respond_to?(:to_sym)
|
|
|
|
@install = @install.to_sym
|
|
|
|
end
|
2013-04-15 19:08:08 +00:00
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# Make sure the version is a symbol if it's not a boolean
|
|
|
|
if @version.respond_to?(:to_sym)
|
|
|
|
@version = @version.to_sym
|
2014-01-17 02:03:38 +00:00
|
|
|
end
|
|
|
|
|
2013-04-15 19:08:08 +00:00
|
|
|
# Make sure the log level is a symbol
|
|
|
|
@log_level = @log_level.to_sym
|
2013-04-16 20:23:00 +00:00
|
|
|
end
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# Like validate, but returns a list of errors to append.
|
|
|
|
#
|
|
|
|
# @return [Array<String>]
|
2013-07-11 02:31:52 +00:00
|
|
|
def validate_base(machine)
|
2013-09-04 23:56:45 +00:00
|
|
|
errors = _detected_errors
|
2013-07-11 02:31:52 +00:00
|
|
|
|
2015-11-23 23:14:32 +00:00
|
|
|
if !present?(log_level)
|
2014-10-31 18:22:09 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.chef.log_level_empty")
|
2013-07-11 02:31:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
errors
|
|
|
|
end
|
2013-01-14 00:41:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|