Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a post_create_command #81

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@ pre_create_command: cp .vagrant_plugins.json {{vagrant_root}}/ && vagrant plugin

The default is unset, or `nil`.

### <a name="config-post-create-command"></a> 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`.

### <a name="config-synced-folders"></a> synced_folders

Allow the user to specify a collection of synced folders on each Vagrant
Expand Down
11 changes: 11 additions & 0 deletions lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down