Conditional action inside resource

I need to put an action inside a resource into a conditional. If the
condition is true, then include that action, if not, don’t. How can I do
this in chef?

eg:

template “/usr/share/tomcat7/bin/setenv.sh” do
source "usr/share/tomcat7/bin/setenv.sh.erb"
owner 'root’
group 'root’
mode '0644’
backup false

Only include the ‘notifies’ line below if some condition is true.

notifies :restart, ‘service[tomcat7]’, :delayed if
node[‘tomcat’][‘tomcat_service_states’].include? 'start’
variables(
:config => node[‘tomcat’]
)
end

Thanks,
Doug.

That’s exactly how I do it. You just need to get your if onto the same line as your notifies so it’s one statement.

template "#{activemq_home}/bin/linux/wrapper.conf" do source 'wrapper.conf.erb' mode 0644 only_if { node['activemq']['use_default_config'] } notifies :restart, 'service[activemq]' if node['activemq']['enabled'] end