Using cookbook_file

I am trying to have Chef deliver a bin file that needs to be run as part of the recipe, but the file is only being delivered at the very end of the recipe. When it reaches the line to run the file I get an error saying that it doesn’t exist, then after everything else runs I see that chef it putting the file in place. Am I using this wrong or is there a better way to do this? Should I just switch to wget or scp to get the file instead?

My recipe sets up the directories, tries to transfer or create the file, execute it then make config changes. If I run the recipe again it will actually run the file and finish off the recipe correctly.

Thank you for your help!

Bridger Larson

Hey Bridger,

You might try setting your cookbook_file resource action to nothing
and using a notifier in your directory resource block to call the
execution of the cookbook_file resource immediately:

cookbook_file "/tmp/testfile" do
source "testfile" # this is the value that would be inferred from
the path parameter
mode "0644"
action :nothing
end

directory "/path/foo" do
user "testuser"
group "testuser"
mode 0755
notifies :run, cookbook_file["/tmp/testfile"], :immediately
end

http://wiki.opscode.com/display/chef/Resources#Resources-Notifications

Hope this helps!

On Tue, Oct 23, 2012 at 11:48 AM, Bridger Larson
Bridger.Larson@sirsidynix.com wrote:

I am trying to have Chef deliver a bin file that needs to be run as part of
the recipe, but the file is only being delivered at the very end of the
recipe. When it reaches the line to run the file I get an error saying that
it doesn’t exist, then after everything else runs I see that chef it putting
the file in place. Am I using this wrong or is there a better way to do
this? Should I just switch to wget or scp to get the file instead?

My recipe sets up the directories, tries to transfer or create the file,
execute it then make config changes. If I run the recipe again it will
actually run the file and finish off the recipe correctly.

Thank you for your help!

Bridger Larson

--
Kevin Karwaski
Operations Engineer @ {Fiksu}