From c25ce9f732c3b3594774f33c63ecda8c48219991 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 8 Apr 2013 14:21:10 -0700 Subject: [PATCH] run_file and single_run mode in CFEngine --- plugins/provisioners/cfengine/config.rb | 10 +++++++++- plugins/provisioners/cfengine/provisioner.rb | 12 ++++++++++++ templates/locales/en.yml | 6 +++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/provisioners/cfengine/config.rb b/plugins/provisioners/cfengine/config.rb index ccfbdd671..fb6364494 100644 --- a/plugins/provisioners/cfengine/config.rb +++ b/plugins/provisioners/cfengine/config.rb @@ -10,6 +10,8 @@ module VagrantPlugins attr_accessor :mode attr_accessor :policy_server_address attr_accessor :repo_gpg_key_url + attr_accessor :run_file + attr_accessor :upload_path attr_accessor :yum_repo_file attr_accessor :yum_repo_url @@ -21,6 +23,8 @@ module VagrantPlugins @mode = UNSET_VALUE @policy_server_address = UNSET_VALUE @repo_gpg_key_url = UNSET_VALUE + @run_file = UNSET_VALUE + @upload_path = UNSET_VALUE @yum_repo_file = UNSET_VALUE @yum_repo_url = UNSET_VALUE end @@ -42,12 +46,16 @@ module VagrantPlugins @mode = :bootstrap if @mode == UNSET_VALUE @mode = @mode.to_sym + @run_file = nil if @run_file == UNSET_VALUE + @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 + @upload_path = "/tmp/vagrant-cfengine-file" if @upload_path == UNSET_VALUE + if @yum_repo_file == UNSET_VALUE @yum_repo_file = "/etc/yum.repos.d/cfengine-community.repo" end @@ -60,7 +68,7 @@ module VagrantPlugins def validate(machine) errors = [] - valid_modes = [:bootstrap, :singlerun] + valid_modes = [:bootstrap, :single_run] errors << I18n.t("vagrant.cfengine_config.invalid_mode") if !valid_modes.include?(@mode) if @mode == :bootstrap diff --git a/plugins/provisioners/cfengine/provisioner.rb b/plugins/provisioners/cfengine/provisioner.rb index 562233b67..74f2b8f6e 100644 --- a/plugins/provisioners/cfengine/provisioner.rb +++ b/plugins/provisioners/cfengine/provisioner.rb @@ -11,6 +11,18 @@ module VagrantPlugins handle_cfengine_installation handle_cfengine_bootstrap if @config.mode == :bootstrap + + if @config.mode == :single_run + # Just let people know + @machine.ui.info(I18n.t("vagrant.cfengine_single_run")) + end + + if @config.run_file + @machine.ui.info(I18n.t("vagrant.cfengine_single_run_execute")) + path = Pathname.new(@config.run_file).expand_path(@machine.env.root_path) + machine.communicate.upload(path.to_s, @config.upload_path) + cfagent("-KI -f #{@config.upload_path}") + end end protected diff --git a/templates/locales/en.yml b/templates/locales/en.yml index ac2151974..533cc36b2 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -10,10 +10,14 @@ en: Installing CFEngine onto machine... cfengine_no_bootstrap: |- CFEngine doesn't require bootstrap. Not bootstrapping. + cfengine_single_run: |- + CFEngine running in "single run" mode. Will execute one file. + cfengine_single_run_execute: |- + Executing run file for CFEngine... cfengine_config: invalid_mode: |- - The mode must be 'bootstrap' or 'singlerun' + The mode must be 'bootstrap' or 'single_run' policy_server_address: |- The policy server address must be set for bootstrapping.