I created one resource which has two actions.
Let's say action:A1 and action:A2. Iam able to call them in one single resource block(test) like this :
test 'Testing the actions' do
action [:a1 ,:a2]
only_if {::File.exists?"/tmp/action_exist.txt"}
end
It is working fine.But what if I want to add the condition on the action like this
Check condition only for action :A1. and simply run action :A2 irrespective of condition.
I tried like this :
test 'Testing the actions' do
action [:A1 ,:A2]
if (action.first=="A1")
puts "yes"
only_if {::File.exists?"/tmp/action_exist.txt" }
end
end
But it's not working. It is executing this condition for both the actions
This is not how Chef works. The resource body isn't a script that is run each action.