diff --git a/plugins/provisioners/cfengine/cap/linux/cfengine_needs_bootstrap.rb b/plugins/provisioners/cfengine/cap/linux/cfengine_needs_bootstrap.rb new file mode 100644 index 000000000..11bb25c89 --- /dev/null +++ b/plugins/provisioners/cfengine/cap/linux/cfengine_needs_bootstrap.rb @@ -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 diff --git a/plugins/provisioners/cfengine/config.rb b/plugins/provisioners/cfengine/config.rb index b3372bc77..77cd98683 100644 --- a/plugins/provisioners/cfengine/config.rb +++ b/plugins/provisioners/cfengine/config.rb @@ -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 diff --git a/plugins/provisioners/cfengine/plugin.rb b/plugins/provisioners/cfengine/plugin.rb index d54985a72..7a0842ba5 100644 --- a/plugins/provisioners/cfengine/plugin.rb +++ b/plugins/provisioners/cfengine/plugin.rb @@ -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 diff --git a/plugins/provisioners/cfengine/provisioner.rb b/plugins/provisioners/cfengine/provisioner.rb index 00e683b7d..c296df18f 100644 --- a/plugins/provisioners/cfengine/provisioner.rb +++ b/plugins/provisioners/cfengine/provisioner.rb @@ -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