From ff5b9c22d138276388a513f945d4afcf423c3b13 Mon Sep 17 00:00:00 2001 From: Hector Castro Date: Sat, 15 Mar 2014 14:54:19 -0400 Subject: [PATCH] Add support for a post_create_command. --- README.md | 13 +++++++++++++ lib/kitchen/driver/vagrant.rb | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index ca162024..2e9b4705 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,19 @@ pre_create_command: cp .vagrant_plugins.json {{vagrant_root}}/ && vagrant plugin The default is unset, or `nil`. +### post\_create\_command + +An optional hook to run a command immediately after the +`vagrant up --no-provisioner` command is executed. + +There is an optional token, `{{vagrant_root}}` that can be used in the +`post_create_command` string which will be expanded by the driver to be the full +path to the sandboxed Vagrant root directory containing the Vagrantfile. This +command will be executed from the directory containing the .kitchen.yml file, +or the `kitchen_root`. + +The default is unset, or `nil`. + ### synced_folders Allow the user to specify a collection of synced folders on each Vagrant diff --git a/lib/kitchen/driver/vagrant.rb b/lib/kitchen/driver/vagrant.rb index 32c1403e..6ce00efd 100644 --- a/lib/kitchen/driver/vagrant.rb +++ b/lib/kitchen/driver/vagrant.rb @@ -68,6 +68,7 @@ def create(state) run cmd set_ssh_state(state) info("Vagrant instance #{instance.to_str} created.") + run_post_create_command end def converge(state) @@ -134,6 +135,12 @@ def run_pre_create_command end end + def run_post_create_command + if config[:post_create_command] + run(config[:post_create_command], :cwd => config[:kitchen_root]) + end + end + def vagrant_root @vagrant_root ||= File.join( config[:kitchen_root], %w{.kitchen kitchen-vagrant}, instance.name @@ -213,6 +220,10 @@ def resolve_config! config[:pre_create_command] = config[:pre_create_command].gsub("{{vagrant_root}}", vagrant_root) end + unless config[:post_create_command].nil? + config[:post_create_command] = + config[:post_create_command].gsub("{{vagrant_root}}", vagrant_root) + end end def vagrant_version