1
votes

I am using vagrant driver and virtualbox provider for testing serverspec. I need to execute some application related script before executing kitchen converge.

I have tried using vagrant provisioning, but I am trying to keep application configuration separately from vagrant configuration.

Is there any way where we can pass some commands to .kitchen.yml file in kitchen? to execute some commands before converging cookbooks.

3

3 Answers

1
votes

If you are trying to run the command on the host system there is pre_create_command. If you mean run something on the guest, that isn't supported. You would be best off making a test fixture recipe or cookbook and adding it to the guest node's run list.

0
votes

@coderanger's suggestion is probably the best approach.

Alternatively, you could try one of the following:

Custom Vagrant box

If the application script is always the same, you could consider creating your own custom Vagrant box were the script has already been executed.

Abuse chef_omnibus_url

.kitchen.yml:

driver:
  name: vagrant

provisioner:
  name: chef_zero
  chef_omnibus_url: "uri_to_your_script/script.sh"
...

script.sh:

#!/bin/sh

# Your script goes here

curl https://www.chef.io/chef/install.sh | sh

(https://www.chef.io/chef/install.sh is the default value for chef_omnibus_url)

0
votes

I like both answers, but they didn't fit my case as well as yours: * 1st deprecated * 2nd not what you need, but VERY good point

However, my solution might help you.

As this is - I would guess now - for TESTING only, then I suggeste to your create a new cookbook (e.g. test_kitchen_support), which you run 1st in run list. You can install all you need there.

This way I found it very niet and it is just testing, so production would use only cookbook.

My problem was that I was sick of creating own vagrant boxes and most that I found didn't suits me well (e.g. they have some hardcodings, or they were very tiny OS version with some default packages missing)

I hope this help somebody.