Basic CFEngine boostrapping

This commit is contained in:
Mitchell Hashimoto 2013-04-08 13:46:03 -07:00
parent 53e15263f5
commit c457285fb6
4 changed files with 50 additions and 4 deletions

View File

@ -135,6 +135,10 @@ module Vagrant
error_key(:failed, "vagrant.actions.box.verify")
end
class CFEngineBootstrapFailed < VagrantError
error_key(:cfengine_bootstrap_failed)
end
class CFEngineInstallFailed < VagrantError
error_key(:cfengine_install_failed)
end

View File

@ -8,6 +8,7 @@ module VagrantPlugins
attr_accessor :force_bootstrap
attr_accessor :install
attr_accessor :mode
attr_accessor :policy_server_address
attr_accessor :repo_gpg_key_url
attr_accessor :yum_repo_file
attr_accessor :yum_repo_url
@ -18,6 +19,7 @@ module VagrantPlugins
@force_bootstrap = UNSET_VALUE
@install = UNSET_VALUE
@mode = UNSET_VALUE
@policy_server_address = UNSET_VALUE
@repo_gpg_key_url = UNSET_VALUE
@yum_repo_file = UNSET_VALUE
@yum_repo_url = UNSET_VALUE
@ -40,6 +42,8 @@ module VagrantPlugins
@mode = :bootstrap if @mode == UNSET_VALUE
@mode = @mode.to_sym
@policy_server_address = nil if @policy_server_address == UNSET_VALUE
if @repo_gpg_key_url == UNSET_VALUE
@repo_gpg_key_url = "http://cfengine.com/pub/gpg.key"
end

View File

@ -10,14 +10,45 @@ module VagrantPlugins
@logger.info("Checking for CFEngine installation...")
handle_cfengine_installation
if @config.mode == :bootstrap
@logger.info("Bootstrapping CFEngine...")
if @machine.guest.capability(:cfengine_needs_bootstrap, @config)
handle_cfengine_bootstrap if @config.mode == :bootstrap
end
protected
# This runs cf-agent with the given arguments.
def cfagent(args, options=nil)
options ||= {}
command = "/var/cfengine/bin/cf-agent #{args}"
@machine.communicate.sudo(command, error_check: options[:error_check]) do |type, data|
if [:stderr, :stdout].include?(type)
# Output the data with the proper color based on the stream.
color = type == :stdout ? :green : :red
# Note: Be sure to chomp the data to avoid the newlines that the
# Chef outputs.
@machine.ui.info(data.chomp, :color => color, :prefix => false)
end
end
end
protected
# This handles checking if the CFEngine installation needs to
# be bootstrapped, and bootstraps if it does.
def handle_cfengine_bootstrap
@logger.info("Bootstrapping CFEngine...")
if !@machine.guest.capability(:cfengine_needs_bootstrap, @config)
@machine.ui.info(I18n.t("vagrant.cfengine_no_bootstrap"))
return
end
# Needs bootstrap, let's determine the parameters
policy_server_address = @config.policy_server_address
@machine.ui.info(I18n.t("vagrant.cfengine_bootstrapping",
policy_server: policy_server_address))
result = cfagent("--bootstrap --policy-server #{policy_server_address}", error_check: false)
raise Vagrant::Errors::CFEngineBootstrapFailed if result != 0
end
# This handles verifying the CFEngine installation, installing it
# if it was requested, and so on. This method will raise exceptions

View File

@ -1,11 +1,15 @@
en:
vagrant:
cfengine_bootstrapping: |-
Bootstrapping CFEngine with policy server: %{policy_server}...
cfengine_cant_detect: |-
Vagrant doesn't support detecting whether CFEngine is installed
for the guest OS running in the machine. Vagrant will assume it is
installed and attempt to continue.
cfengine_installing: |-
Installing CFEngine onto machine...
cfengine_no_bootstrap: |-
CFEngine doesn't require bootstrap. Not bootstrapping.
general:
batch_unexpected_error: |-
@ -106,6 +110,9 @@ en:
The box '%{name}' is still stored on disk in the Vagrant 1.0.x
format. This box must be upgraded in order to work properly with
this version of Vagrant.
cfengine_bootstrap_failed: |-
Failed to bootstrap CFEngine. Please see the output above to
see what went wrong and address the issue.
cfengine_install_failed: |-
After installing CFEngine, Vagrant still can't detect a proper
CFEngine installation. Please verify that CFEngine was properly