2015-11-23 23:14:32 +00:00
|
|
|
require "vagrant/util/presence"
|
2013-08-29 18:36:37 +00:00
|
|
|
require "vagrant/util/which"
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
require_relative "base_runner"
|
2014-10-30 15:21:56 +00:00
|
|
|
|
2013-01-14 00:41:32 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Chef
|
|
|
|
module Config
|
2014-10-31 18:22:09 +00:00
|
|
|
class ChefClient < BaseRunner
|
2015-11-23 23:14:32 +00:00
|
|
|
include Vagrant::Util::Presence
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# The URL endpoint to the Chef Server.
|
|
|
|
# @return [String]
|
2013-01-14 00:41:32 +00:00
|
|
|
attr_accessor :chef_server_url
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The path on disk to the Chef client key,
|
|
|
|
# @return [String]
|
2013-01-14 00:41:32 +00:00
|
|
|
attr_accessor :client_key_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# Delete the client key when the VM is destroyed. Default is false.
|
|
|
|
# @return [true, false]
|
2013-08-29 17:50:50 +00:00
|
|
|
attr_accessor :delete_client
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# Delete the node when the VM is destroyed. Default is false.
|
|
|
|
# @return [true, false]
|
2013-08-29 17:50:50 +00:00
|
|
|
attr_accessor :delete_node
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The path to the validation key on disk.
|
|
|
|
# @return [String]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :validation_key_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The name of the validation client.
|
|
|
|
# @return [String]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :validation_client_name
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
|
2014-10-30 19:32:10 +00:00
|
|
|
@chef_server_url = UNSET_VALUE
|
|
|
|
@client_key_path = UNSET_VALUE
|
|
|
|
@delete_client = UNSET_VALUE
|
|
|
|
@delete_node = UNSET_VALUE
|
|
|
|
@validation_key_path = UNSET_VALUE
|
|
|
|
@validation_client_name = UNSET_VALUE
|
2013-04-15 19:08:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
|
|
|
super
|
2013-01-14 00:41:32 +00:00
|
|
|
|
2014-10-30 19:32:10 +00:00
|
|
|
@chef_server_url = nil if @chef_server_url == UNSET_VALUE
|
2015-07-09 22:55:55 +00:00
|
|
|
@client_key_path = nil if @client_key_path == UNSET_VALUE
|
2014-10-30 19:32:10 +00:00
|
|
|
@delete_client = false if @delete_client == UNSET_VALUE
|
|
|
|
@delete_node = false if @delete_node == UNSET_VALUE
|
2013-04-15 19:08:08 +00:00
|
|
|
@validation_client_name = "chef-validator" if @validation_client_name == UNSET_VALUE
|
2014-10-30 19:32:10 +00:00
|
|
|
@validation_key_path = nil if @validation_key_path == UNSET_VALUE
|
2013-04-15 19:08:08 +00:00
|
|
|
end
|
2013-01-14 00:41:32 +00:00
|
|
|
|
2013-01-18 21:12:02 +00:00
|
|
|
def validate(machine)
|
2014-10-31 18:22:09 +00:00
|
|
|
errors = validate_base(machine)
|
2014-10-30 15:42:15 +00:00
|
|
|
|
2015-11-23 23:14:32 +00:00
|
|
|
if !present?(chef_server_url)
|
2014-10-30 15:42:15 +00:00
|
|
|
errors << I18n.t("vagrant.config.chef.server_url_empty")
|
|
|
|
end
|
|
|
|
|
2015-11-23 23:14:32 +00:00
|
|
|
if !present?(validation_key_path)
|
2014-10-30 15:42:15 +00:00
|
|
|
errors << I18n.t("vagrant.config.chef.validation_key_path")
|
|
|
|
end
|
2013-01-14 00:41:32 +00:00
|
|
|
|
2013-01-18 21:12:02 +00:00
|
|
|
{ "chef client provisioner" => errors }
|
2013-01-14 00:41:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|