I need a way to run parts of chef recipes only in case of converge action in Test Kitchen.
I found a way to do it for ChefSpec:
unless defined?(ChefSpec)
cookbook_file "/home/#{node['user']}/script.sh" do
source 'install.sh'
owner node['user']
mode '0755'
action :create
end
end
How I can do it for Kitchen tool?
This requirement has been discussed in detail on a feature request on Github.
There are two ways to do this. One is to define an environment variable such as
TEST_KITCHEN, then use it in recipe withifcondition,only_ifornot_ifguards.Below should work:
Set the environment variable:
Run the resource conditionally:
Other way is to use a node attribute, something like
node['test_kitchen']set totrueand use it to run actions conditionally.