Start working on CFEngine bootstrap

This commit is contained in:
Mitchell Hashimoto 2013-04-08 13:28:54 -07:00
parent 8f9a5671de
commit 53e15263f5
4 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,34 @@
require "log4r"
module VagrantPlugins
module CFEngine
module Cap
module Linux
module CFEngineNeedsBootstrap
def self.cfengine_needs_bootstrap(machine, config)
logger = Log4r::Logger.new("vagrant::plugins::cfengine::cap_linux_cfengine_bootstrap")
machine.communicate.tap do |comm|
# We hardcode fixing the permissions on /var/cfengine/ppkeys/, if it exists,
# because otherwise CFEngine will fail to bootstrap.
if comm.test("test -d /var/cfengine/ppkeys", :sudo => true)
logger.debug("Fixing permissions on /var/cfengine/ppkeys")
comm.sudo("chmod -R 600 /var/cfengine/ppkeys")
end
logger.debug("Checking if CFEngine is bootstrapped...")
bootstrapped = comm.test("test -f /var/cfengine/policy_server.dat", :sudo => true)
if bootstrapped && !config.force_bootstrap
logger.info("CFEngine already bootstrapped, no need to do it again")
return false
end
logger.info("CFEngine needs bootstrap.")
return true
end
end
end
end
end
end
end

View File

@ -3,9 +3,11 @@ require "vagrant"
module VagrantPlugins
module CFEngine
class Config < Vagrant.plugin("2", :config)
attr_accessor :install
attr_accessor :deb_repo_file
attr_accessor :deb_repo_line
attr_accessor :force_bootstrap
attr_accessor :install
attr_accessor :mode
attr_accessor :repo_gpg_key_url
attr_accessor :yum_repo_file
attr_accessor :yum_repo_url
@ -13,7 +15,9 @@ module VagrantPlugins
def initialize
@deb_repo_file = UNSET_VALUE
@deb_repo_line = UNSET_VALUE
@force_bootstrap = UNSET_VALUE
@install = UNSET_VALUE
@mode = UNSET_VALUE
@repo_gpg_key_url = UNSET_VALUE
@yum_repo_file = UNSET_VALUE
@yum_repo_url = UNSET_VALUE
@ -28,9 +32,14 @@ module VagrantPlugins
@deb_repo_line = "deb http://cfengine.com/pub/apt $(lsb_release -cs) main"
end
@force_bootstrap = false if @force_bootstrap == UNSET_VALUE
@install = true if @install == UNSET_VALUE
@install = @install.to_sym if @install.respond_to?(:to_sym)
@mode = :bootstrap if @mode == UNSET_VALUE
@mode = @mode.to_sym
if @repo_gpg_key_url == UNSET_VALUE
@repo_gpg_key_url = "http://cfengine.com/pub/gpg.key"
end

View File

@ -18,6 +18,11 @@ module VagrantPlugins
Cap::Debian::CFEngineInstall
end
guest_capability("linux", "cfengine_needs_bootstrap") do
require_relative "cap/linux/cfengine_needs_bootstrap"
Cap::Linux::CFEngineNeedsBootstrap
end
guest_capability("linux", "cfengine_installed") do
require_relative "cap/linux/cfengine_installed"
Cap::Linux::CFEngineInstalled

View File

@ -1,10 +1,20 @@
require "log4r"
require "vagrant"
module VagrantPlugins
module CFEngine
class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
@logger = Log4r::Logger.new("vagrant::plugins::cfengine")
@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)
end
end
end
protected