I've been trying to find the answer to this in the chef docs and through Google, but I've not been able to come up with anything. I'm not a ruby guy (yet), so the answer to this might stem from my approaching the problem with "just enough ruby for Chef". Here's what I want to do: in my deploy
resource, in the before_migrate
attribute, I want to execute a resource in my current recipe. What I am doing currently is to just stuff the resource into the block itself, but I know there must be a better way to do it.
before_migrate do
template "#{app_root}/#{applet_name}/local_settings.py" do
source "local_settings.py.erb"
owner app_config['user']
group app_config['group']
variables(
:database_name => app_config['postgresql']['database_name'],
:user => app_config['postgresql']['user'],
:password => app_config['postgresql']['password']
)
action :create
end
end
What I'm aiming for is something like
before_migrate do
"template #{app_root}/#{applet_name}/local_settings.py".execute
end
So I can re-use that template code. Thanks!
You could specify the resource outside of the "deploy" resource with an action of nothing and then, in the *before_migrate* do something like:
before_migrate do
ruby_block "notify_template" do
block do
true
end
action :create
notifies :create, "template[#{app_root}/#{applet_name}/local_settings.py]", :immediately
end
end
That way, you can notify it when you need it.
Thanks to the great guys in the #chef IRC channel, I solved my problem. The notification resource needs to be accessed directly, using
Chef::Resource::Notification.new("template[#{app_root}/#{applet_name}/local_settings.py", :create)
Which will notify the template
resource to run the :create
action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With