david
david

Reputation: 761

how to use a 'not_if' condition on a template resource

I'm trying to use a 'not_if' condition in a template resource as showcased by docs.chef.io

template "/tmp/somefile" do
  mode '0644'
  source "somefile.erb"
  not_if { node[:some_value] }
end

I'm new to chef and I'm unsure how to proceed to create something that effectively does the following:

if 'instance' (in node['project']['instance']) == nil 
do NOT do anything for this template

I would like to use the not_if condition but I don't know how to check for 'instance' == nil.

I would appreciate any help. Thank you,

Upvotes: 0

Views: 4072

Answers (1)

Tejay Cardon
Tejay Cardon

Reputation: 4223

how about

not_if { node['project']['instance'].nil? }

This will check that the value of node['project']['instance'] is not nil. It will also fail if node['project'] happens to be nil, so if you aren't sure, you'll need:

not_if { node['project'].nil? || node['project']['instance'].nil? }

Upvotes: 1

Related Questions