Tips for running a script before kitchen converge?


#1

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure this
is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if possible.

Thanks,
Robert


#2

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option may
be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger rfreiberger@gmail.com
wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure this
is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


#3

You can tell vagrant to use it’s shell provisioner, but you’d likely need
to provide a custom vagrantfile.erb (there’s a parameter for that in the
kitchen-vagrant driver).

The pre_create_command happens before the vagrant up, so that’d be
something more for prepping your host environment (maybe staging sync’d
folders or something).

Steve

On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe brandocorp@gmail.com wrote:

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option may
be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger rfreiberger@gmail.com
wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure
this is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


Steven Murawski
Community Software Development Engineer @ Chef
Microsoft MVP - PowerShell
http://stevenmurawski.com


#4

Hello,

Thanks Brandon and Steve for your recommendations. Apologies as I was away
but I’m testing these features now. My original goal was to edit a Vagrant
box and make some changes (just add a Ruby script to execute during start
up) but after reading, might be easier to keep this separate.

Thanks again,
Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski steven.murawski@gmail.com
wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely need
to provide a custom vagrantfile.erb (there’s a parameter for that in the
kitchen-vagrant driver).

The pre_create_command happens before the vagrant up, so that’d be
something more for prepping your host environment (maybe staging sync’d
folders or something).

Steve

On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe brandocorp@gmail.com
wrote:

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option
may be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger <rfreiberger@gmail.com

wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure
this is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


Steven Murawski
Community Software Development Engineer @ Chef
Microsoft MVP - PowerShell
http://stevenmurawski.com


#5

I am struggling with a similar scenario. As part of our chefdk bootstrap, we package up a set of cookbooks using berks package. We have a a curl bash that end users execute to install/update the dev environment. We have been testing using test kitchen w/ the chef provisioner but because the testing doesn’t fully simulate our real environment (chef may or may not be installed, bash script to start the process not run) we have had a couple of defects escape testing. The pre_create_command doesn’t work because we want these set of commands to be run before every converge, not just the first create.I have considered using the vagrantfiles directive with a custom vagrant file, but its not clear to me that would help since that only seems to get executed on create as well. I could create a script that does this, but that i somewhat unsatisfying because it fights against the muscle memory for all of our other cookbooks. Has anyone come across a good solution to resolve this in test kitchen? It feels like a pre_converge_command would be optimal for this sort of scenario.

Thanks, Brian

----- Original message -----

From: Robert Freiberger <rfreiberger@gmail.com>

To: "chef@lists.opscode.com" <chef@lists.opscode.com>

Cc:

Subject: [chef] Re: Re: Re: Tips for running a script before kitchen converge?

Date: Tue, Sep 29, 2015 5:46 PM

Hello,
Thanks Brandon and Steve for your recommendations. Apologies as I was away but I’m testing these features now. My original goal was to edit a Vagrant box and make some changes (just add a Ruby script to execute during start up) but after reading, might be easier to keep this separate. Thanks again,Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski <steven.murawski@gmail.com> wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely need to provide a custom vagrantfile.erb (there’s a parameter for that in the kitchen-vagrant driver).
The pre_create_command happens before the vagrant up, so that’d be something more for prepping your host environment (maybe staging sync’d folders or something). Steve
On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe <brandocorp@gmail.com> wrote:
Hey Robert, I'm not sure what's in the script, but the `pre_create_command` option may be what you're looking for. I'm assuming you're using kitchen-vagrant. https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger <rfreiberger@gmail.com> wrote:
Hello, I'm working on a simple Vagrant box with Test Kitchen and pretty sure this is a simple request. Is it possible to execute a script before kitchen converge? Maybe I'm not seeing this, but I checked the options from Test Kitchen. I really would like to stay away from customizing the box file if possible. Thanks,Robert


Steven MurawskiCommunity Software Development Engineer @ ChefMicrosoft MVP - PowerShell

http://stevenmurawski.com


#6

Looks like it’s in the works:

You might have to use regular Vagrant for now as that supports multiple
provisioners (i.e. run the shell provisioner before Chef)

On 29 September 2015 at 20:18, Brian O’Connell boc@us.ibm.com wrote:

I am struggling with a similar scenario. As part of our chefdk bootstrap,
we package up a set of cookbooks using berks package. We have a a curl
bash that end users execute to install/update the dev environment.

We have been testing using test kitchen w/ the chef provisioner but
because the testing doesn’t fully simulate our real environment (chef may
or may not be installed, bash script to start the process not run) we have
had a couple of defects escape testing.

The pre_create_command doesn’t work because we want these set of commands
to be run before every converge, not just the first create.
I have considered using the vagrantfiles directive with a custom vagrant
file, but its not clear to me that would help since that only seems to get
executed on create as well.

I could create a script that does this, but that i somewhat unsatisfying
because it fights against the muscle memory for all of our other cookbooks.

Has anyone come across a good solution to resolve this in test kitchen?
It feels like a pre_converge_command would be optimal for this sort of
scenario.

Thanks,
Brian

----- Original message -----
From: Robert Freiberger rfreiberger@gmail.com
To: "chef@lists.opscode.com" chef@lists.opscode.com
Cc:
Subject: [chef] Re: Re: Re: Tips for running a script before kitchen
converge?
Date: Tue, Sep 29, 2015 5:46 PM

Hello,

Thanks Brandon and Steve for your recommendations. Apologies as I was away
but I’m testing these features now. My original goal was to edit a Vagrant
box and make some changes (just add a Ruby script to execute during start
up) but after reading, might be easier to keep this separate.

Thanks again,
Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski steven.murawski@gmail.com
wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely need
to provide a custom vagrantfile.erb (there’s a parameter for that in the
kitchen-vagrant driver).

The pre_create_command happens before the vagrant up, so that’d be
something more for prepping your host environment (maybe staging sync’d
folders or something).

Steve

On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe brandocorp@gmail.com
wrote:

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option may
be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger rfreiberger@gmail.com
wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure this
is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


Steven Murawski
Community Software Development Engineer @ Chef
Microsoft MVP - PowerShell
http://stevenmurawski.com


#7

I had a similar issue and came to this solution:

In my case I have the whole ~/ directory under control, and I wanted it to
apply globally rather than repreating in every project kitchen /
Vagrantfile. Should work for local ones too

Just for inspiration…

HTH, Torben

On Wed, Sep 30, 2015 at 5:14 PM, Yoshi Spendiff yoshi@spendiff.net wrote:

Looks like it’s in the works:
https://github.com/test-kitchen/test-kitchen/issues/329

You might have to use regular Vagrant for now as that supports multiple
provisioners (i.e. run the shell provisioner before Chef)

On 29 September 2015 at 20:18, Brian O’Connell boc@us.ibm.com wrote:

I am struggling with a similar scenario. As part of our chefdk
bootstrap, we package up a set of cookbooks using berks package. We have
a a curl bash that end users execute to install/update the dev environment.

We have been testing using test kitchen w/ the chef provisioner but
because the testing doesn’t fully simulate our real environment (chef may
or may not be installed, bash script to start the process not run) we have
had a couple of defects escape testing.

The pre_create_command doesn’t work because we want these set of commands
to be run before every converge, not just the first create.
I have considered using the vagrantfiles directive with a custom vagrant
file, but its not clear to me that would help since that only seems to get
executed on create as well.

I could create a script that does this, but that i somewhat unsatisfying
because it fights against the muscle memory for all of our other cookbooks.

Has anyone come across a good solution to resolve this in test kitchen?
It feels like a pre_converge_command would be optimal for this sort of
scenario.

Thanks,
Brian

----- Original message -----
From: Robert Freiberger rfreiberger@gmail.com
To: "chef@lists.opscode.com" chef@lists.opscode.com
Cc:
Subject: [chef] Re: Re: Re: Tips for running a script before kitchen
converge?
Date: Tue, Sep 29, 2015 5:46 PM

Hello,

Thanks Brandon and Steve for your recommendations. Apologies as I was
away but I’m testing these features now. My original goal was to edit a
Vagrant box and make some changes (just add a Ruby script to execute during
start up) but after reading, might be easier to keep this separate.

Thanks again,
Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski steven.murawski@gmail.com
wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely need
to provide a custom vagrantfile.erb (there’s a parameter for that in the
kitchen-vagrant driver).

The pre_create_command happens before the vagrant up, so that’d be
something more for prepping your host environment (maybe staging sync’d
folders or something).

Steve

On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe brandocorp@gmail.com
wrote:

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option
may be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger <rfreiberger@gmail.com

wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure
this is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


Steven Murawski
Community Software Development Engineer @ Chef
Microsoft MVP - PowerShell
http://stevenmurawski.com


#8

Torben - Thanks for sharing. Its a nifty solution. In my case, I have things I want to do outside the VMs to prepare for each converge. I want to package up some files to be placed into the the data_path. I am not sure how to handle that in vagrantfile.

----- Original message -----

From: Torben Knerr <mail@tknerr.de>

To: yoshi@spendiff.net

Cc: "chef@lists.opscode.com" <chef@lists.opscode.com>

Subject: [chef] Re: Re: Re: Re: Re: Re: Tips for running a script before kitchen converge?

Date: Wed, Sep 30, 2015 1:11 PM

I had a similar issue and came to this solution: * create a global ~/.kitchen/config.yml which tells to run the provisioners for the vagrant driver (e.g. https://github.com/tknerr/bills-kitchen/blob/master/files/home/.kitchen/config.yml) * create a global ~/.vagrant.d/Vagrantfile with a shell provisioner (e.g. https://github.com/tknerr/bills-kitchen/blob/master/files/home/.vagrant.d/Vagrantfile#L23-L26) In my case I have the whole ~/ directory under control, and I wanted it to apply globally rather than repreating in every project kitchen / Vagrantfile. Should work for local ones too Just for inspiration… HTH, Torben
On Wed, Sep 30, 2015 at 5:14 PM, Yoshi Spendiff <yoshi@spendiff.net> wrote:

Looks like it's in the works: https://github.com/test-kitchen/test-kitchen/issues/329 You might have to use regular Vagrant for now as that supports multiple provisioners (i.e. run the shell provisioner before Chef) On 29 September 2015 at 20:18, Brian O'Connell <boc@us.ibm.com> wrote:
I am struggling with a similar scenario. As part of our chefdk bootstrap, we package up a set of cookbooks using berks package. We have a a curl bash that end users execute to install/update the dev environment. We have been testing using test kitchen w/ the chef provisioner but because the testing doesn't fully simulate our real environment (chef may or may not be installed, bash script to start the process not run) we have had a couple of defects escape testing. The pre_create_command doesn't work because we want these set of commands to be run before every converge, not just the first create.I have considered using the vagrantfiles directive with a custom vagrant file, but its not clear to me that would help since that only seems to get executed on create as well. I could create a script that does this, but that i somewhat unsatisfying because it fights against the muscle memory for all of our other cookbooks. Has anyone come across a good solution to resolve this in test kitchen? It feels like a pre_converge_command would be optimal for this sort of scenario.

Thanks, Brian

----- Original message -----

From: Robert Freiberger <rfreiberger@gmail.com>

To: “chef@lists.opscode.com” <chef@lists.opscode.com>

Cc:

Subject: [chef] Re: Re: Re: Tips for running a script before kitchen converge?

Date: Tue, Sep 29, 2015 5:46 PM

Hello,
Thanks Brandon and Steve for your recommendations. Apologies as I was away but I’m testing these features now. My original goal was to edit a Vagrant box and make some changes (just add a Ruby script to execute during start up) but after reading, might be easier to keep this separate. Thanks again,Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski <steven.murawski@gmail.com> wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely need to provide a custom vagrantfile.erb (there’s a parameter for that in the kitchen-vagrant driver).
The pre_create_command happens before the vagrant up, so that’d be something more for prepping your host environment (maybe staging sync’d folders or something). Steve
On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe <brandocorp@gmail.com> wrote:
Hey Robert, I'm not sure what's in the script, but the `pre_create_command` option may be what you're looking for. I'm assuming you're using kitchen-vagrant. https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger <rfreiberger@gmail.com> wrote:
Hello, I'm working on a simple Vagrant box with Test Kitchen and pretty sure this is a simple request. Is it possible to execute a script before kitchen converge? Maybe I'm not seeing this, but I checked the options from Test Kitchen. I really would like to stay away from customizing the box file if possible. Thanks,Robert


Steven MurawskiCommunity Software Development Engineer @ ChefMicrosoft MVP - PowerShell

http://stevenmurawski.com


#9

Hey Brian,

the vagrant-triggers plugin might come in handy for this:

HTH, Torben

On Wed, Sep 30, 2015 at 7:35 PM, Brian O’Connell boc@us.ibm.com wrote:

Torben -
Thanks for sharing. Its a nifty solution. In my case, I have things I
want to do outside the VMs to prepare for each converge. I want to package
up some files to be placed into the the data_path. I am not sure how to
handle that in vagrantfile.

----- Original message -----
From: Torben Knerr mail@tknerr.de
To: yoshi@spendiff.net
Cc: "chef@lists.opscode.com" chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: Re: Re: Tips for running a script before
kitchen converge?
Date: Wed, Sep 30, 2015 1:11 PM

I had a similar issue and came to this solution:

In my case I have the whole ~/ directory under control, and I wanted it to
apply globally rather than repreating in every project kitchen /
Vagrantfile. Should work for local ones too

Just for inspiration…

HTH, Torben

On Wed, Sep 30, 2015 at 5:14 PM, Yoshi Spendiff yoshi@spendiff.net
wrote:

Looks like it’s in the works:
https://github.com/test-kitchen/test-kitchen/issues/329

You might have to use regular Vagrant for now as that supports multiple
provisioners (i.e. run the shell provisioner before Chef)

On 29 September 2015 at 20:18, Brian O’Connell boc@us.ibm.com wrote:

I am struggling with a similar scenario. As part of our chefdk bootstrap,
we package up a set of cookbooks using berks package. We have a a curl
bash that end users execute to install/update the dev environment.

We have been testing using test kitchen w/ the chef provisioner but
because the testing doesn’t fully simulate our real environment (chef may
or may not be installed, bash script to start the process not run) we have
had a couple of defects escape testing.

The pre_create_command doesn’t work because we want these set of commands
to be run before every converge, not just the first create.
I have considered using the vagrantfiles directive with a custom vagrant
file, but its not clear to me that would help since that only seems to get
executed on create as well.

I could create a script that does this, but that i somewhat unsatisfying
because it fights against the muscle memory for all of our other cookbooks.

Has anyone come across a good solution to resolve this in test kitchen?
It feels like a pre_converge_command would be optimal for this sort of
scenario.

Thanks,
Brian

----- Original message -----
From: Robert Freiberger rfreiberger@gmail.com
To: "chef@lists.opscode.com" chef@lists.opscode.com
Cc:
Subject: [chef] Re: Re: Re: Tips for running a script before kitchen
converge?
Date: Tue, Sep 29, 2015 5:46 PM

Hello,

Thanks Brandon and Steve for your recommendations. Apologies as I was away
but I’m testing these features now. My original goal was to edit a Vagrant
box and make some changes (just add a Ruby script to execute during start
up) but after reading, might be easier to keep this separate.

Thanks again,
Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski steven.murawski@gmail.com
wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely need
to provide a custom vagrantfile.erb (there’s a parameter for that in the
kitchen-vagrant driver).

The pre_create_command happens before the vagrant up, so that’d be
something more for prepping your host environment (maybe staging sync’d
folders or something).

Steve

On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe brandocorp@gmail.com
wrote:

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option may
be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger rfreiberger@gmail.com
wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure this
is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


Steven Murawski
Community Software Development Engineer @ Chef
Microsoft MVP - PowerShell
http://stevenmurawski.com


#10

Correct me if I’m wrong but to get that working you’d first have to
configure test kitchen to call a vagrant provisioner like shell, have the
vagrant provisioner essentially do nothing and configure a trigger to run
before that vagrant provision to complete the pre test kitchen provisioner
steps.

Seems like a lot of fuss when something as a simple as a command alias to
do pre-commands + provision in your bash_profile (plus a script if the
commands are complex) would do the job.

On 30 September 2015 at 13:12, Torben Knerr mail@tknerr.de wrote:

Hey Brian,

the vagrant-triggers plugin might come in handy for this:
https://github.com/emyl/vagrant-triggers

HTH, Torben

On Wed, Sep 30, 2015 at 7:35 PM, Brian O’Connell boc@us.ibm.com wrote:

Torben -
Thanks for sharing. Its a nifty solution. In my case, I have things I
want to do outside the VMs to prepare for each converge. I want to package
up some files to be placed into the the data_path. I am not sure how to
handle that in vagrantfile.

----- Original message -----
From: Torben Knerr mail@tknerr.de
To: yoshi@spendiff.net
Cc: "chef@lists.opscode.com" chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: Re: Re: Tips for running a script before
kitchen converge?
Date: Wed, Sep 30, 2015 1:11 PM

I had a similar issue and came to this solution:

In my case I have the whole ~/ directory under control, and I wanted it
to apply globally rather than repreating in every project kitchen /
Vagrantfile. Should work for local ones too

Just for inspiration…

HTH, Torben

On Wed, Sep 30, 2015 at 5:14 PM, Yoshi Spendiff yoshi@spendiff.net
wrote:

Looks like it’s in the works:
https://github.com/test-kitchen/test-kitchen/issues/329

You might have to use regular Vagrant for now as that supports multiple
provisioners (i.e. run the shell provisioner before Chef)

On 29 September 2015 at 20:18, Brian O’Connell boc@us.ibm.com wrote:

I am struggling with a similar scenario. As part of our chefdk
bootstrap, we package up a set of cookbooks using berks package. We have
a a curl bash that end users execute to install/update the dev environment.

We have been testing using test kitchen w/ the chef provisioner but
because the testing doesn’t fully simulate our real environment (chef may
or may not be installed, bash script to start the process not run) we have
had a couple of defects escape testing.

The pre_create_command doesn’t work because we want these set of commands
to be run before every converge, not just the first create.
I have considered using the vagrantfiles directive with a custom vagrant
file, but its not clear to me that would help since that only seems to get
executed on create as well.

I could create a script that does this, but that i somewhat unsatisfying
because it fights against the muscle memory for all of our other cookbooks.

Has anyone come across a good solution to resolve this in test kitchen?
It feels like a pre_converge_command would be optimal for this sort of
scenario.

Thanks,
Brian

----- Original message -----
From: Robert Freiberger rfreiberger@gmail.com
To: "chef@lists.opscode.com" chef@lists.opscode.com
Cc:
Subject: [chef] Re: Re: Re: Tips for running a script before kitchen
converge?
Date: Tue, Sep 29, 2015 5:46 PM

Hello,

Thanks Brandon and Steve for your recommendations. Apologies as I was
away but I’m testing these features now. My original goal was to edit a
Vagrant box and make some changes (just add a Ruby script to execute during
start up) but after reading, might be easier to keep this separate.

Thanks again,
Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski steven.murawski@gmail.com
wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely need
to provide a custom vagrantfile.erb (there’s a parameter for that in the
kitchen-vagrant driver).

The pre_create_command happens before the vagrant up, so that’d be
something more for prepping your host environment (maybe staging sync’d
folders or something).

Steve

On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe brandocorp@gmail.com
wrote:

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option
may be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger <rfreiberger@gmail.com

wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure
this is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


Steven Murawski
Community Software Development Engineer @ Chef
Microsoft MVP - PowerShell
http://stevenmurawski.com


#11

Or better yet a Thor task

On 30 September 2015 at 14:17, Yoshi Spendiff yoshi@spendiff.net wrote:

Correct me if I’m wrong but to get that working you’d first have to
configure test kitchen to call a vagrant provisioner like shell, have the
vagrant provisioner essentially do nothing and configure a trigger to run
before that vagrant provision to complete the pre test kitchen provisioner
steps.

Seems like a lot of fuss when something as a simple as a command alias to
do pre-commands + provision in your bash_profile (plus a script if the
commands are complex) would do the job.

On 30 September 2015 at 13:12, Torben Knerr mail@tknerr.de wrote:

Hey Brian,

the vagrant-triggers plugin might come in handy for this:
https://github.com/emyl/vagrant-triggers

HTH, Torben

On Wed, Sep 30, 2015 at 7:35 PM, Brian O’Connell boc@us.ibm.com wrote:

Torben -
Thanks for sharing. Its a nifty solution. In my case, I have things
I want to do outside the VMs to prepare for each converge. I want to
package up some files to be placed into the the data_path. I am not sure
how to handle that in vagrantfile.

----- Original message -----
From: Torben Knerr mail@tknerr.de
To: yoshi@spendiff.net
Cc: "chef@lists.opscode.com" chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Re: Re: Re: Tips for running a script before
kitchen converge?
Date: Wed, Sep 30, 2015 1:11 PM

I had a similar issue and came to this solution:

In my case I have the whole ~/ directory under control, and I wanted it
to apply globally rather than repreating in every project kitchen /
Vagrantfile. Should work for local ones too

Just for inspiration…

HTH, Torben

On Wed, Sep 30, 2015 at 5:14 PM, Yoshi Spendiff yoshi@spendiff.net
wrote:

Looks like it’s in the works:
https://github.com/test-kitchen/test-kitchen/issues/329

You might have to use regular Vagrant for now as that supports multiple
provisioners (i.e. run the shell provisioner before Chef)

On 29 September 2015 at 20:18, Brian O’Connell boc@us.ibm.com wrote:

I am struggling with a similar scenario. As part of our chefdk
bootstrap, we package up a set of cookbooks using berks package. We have
a a curl bash that end users execute to install/update the dev environment.

We have been testing using test kitchen w/ the chef provisioner but
because the testing doesn’t fully simulate our real environment (chef may
or may not be installed, bash script to start the process not run) we have
had a couple of defects escape testing.

The pre_create_command doesn’t work because we want these set of
commands to be run before every converge, not just the first create.
I have considered using the vagrantfiles directive with a custom vagrant
file, but its not clear to me that would help since that only seems to get
executed on create as well.

I could create a script that does this, but that i somewhat unsatisfying
because it fights against the muscle memory for all of our other cookbooks.

Has anyone come across a good solution to resolve this in test kitchen?
It feels like a pre_converge_command would be optimal for this sort of
scenario.

Thanks,
Brian

----- Original message -----
From: Robert Freiberger rfreiberger@gmail.com
To: "chef@lists.opscode.com" chef@lists.opscode.com
Cc:
Subject: [chef] Re: Re: Re: Tips for running a script before kitchen
converge?
Date: Tue, Sep 29, 2015 5:46 PM

Hello,

Thanks Brandon and Steve for your recommendations. Apologies as I was
away but I’m testing these features now. My original goal was to edit a
Vagrant box and make some changes (just add a Ruby script to execute during
start up) but after reading, might be easier to keep this separate.

Thanks again,
Robert

On Fri, Sep 18, 2015 at 6:42 PM Steve Murawski <
steven.murawski@gmail.com> wrote:

You can tell vagrant to use it’s shell provisioner, but you’d likely
need to provide a custom vagrantfile.erb (there’s a parameter for that in
the kitchen-vagrant driver).

The pre_create_command happens before the vagrant up, so that’d be
something more for prepping your host environment (maybe staging sync’d
folders or something).

Steve

On Fri, Sep 18, 2015 at 4:44 AM, Brandon Raabe brandocorp@gmail.com
wrote:

Hey Robert,

I’m not sure what’s in the script, but the pre_create_command option
may be what you’re looking for. I’m assuming you’re using kitchen-vagrant.

https://github.com/test-kitchen/kitchen-vagrant#-pre_create_command

On Thu, Sep 17, 2015 at 2:53 PM, Robert Freiberger <
rfreiberger@gmail.com> wrote:

Hello,

I’m working on a simple Vagrant box with Test Kitchen and pretty sure
this is a simple request. Is it possible to execute a script before kitchen
converge? Maybe I’m not seeing this, but I checked the options from Test
Kitchen.

I really would like to stay away from customizing the box file if
possible.

Thanks,
Robert


Steven Murawski
Community Software Development Engineer @ Chef
Microsoft MVP - PowerShell
http://stevenmurawski.com