In this part of a Chef recipe, there are 4 execute
resources. They should only run when a file does not exists. This is added as a condition to the first resource, which then triggers the entire chain to be run.
# Set up default SSL cert
execute "defaultcert1" do
not_if {File.exist?("/vol/webserver/cert")}
command "mkdir /vol/webserver/cert"
notifies :run, "execute[defaultcert2]", :immediately
end
execute "defaultcert2" do
action :nothing
command "ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /vol/webserver/cert/server.crt"
notifies :run, "execute[defaultcert3]", :immediately
end
execute "defaultcert3" do
action :nothing
command "ln -s /etc/ssl/private/ssl-cert-snakeoil.key /vol/webserver/cert/server.key"
notifies :run, "execute[defaultcert4]", :immediately
end
execute "defaultcert4" do
action :nothing
command "chown -R ubuntu:ubuntu /vol/webserver/cert"
end
As you can see, it's a rather large bit of code to guard just 4 commands. Is there a better way to do this?