Searching files/ to see if file exists

Hi all, I need to determine if a file is included/exists in the files/*
subdir under any appropriate folder for the current node, is there any
way I can do this? I looked through the chef code and see theres a
get_filename method as part of the cookbook code, is this usable from
within cookbooks and if so can someone point to an example of how it
would be used?

Thanks,

you can do this with raw ruby code inside recipe:

if File.exists?('/path/to/file')
... add some resource
end

note. this is compile time check, so it will be false if the file is being
created as part of the chef run. use ruby_block or custom lwrp for run time
checks

On Fri, May 2, 2014 at 9:20 AM, Julio Lajara ju2wheels@gmail.com wrote:

Hi all, I need to determine if a file is included/exists in the files/*
subdir under any appropriate folder for the current node, is there any way
I can do this? I looked through the chef code and see theres a get_filename
method as part of the cookbook code, is this usable from within cookbooks
and if so can someone point to an example of how it would be used?

Thanks,

On 5/2/14, 9:20 AM, Julio Lajara wrote:

Hi all, I need to determine if a file is included/exists in the
files/* subdir under any appropriate folder for the current node, is
there any way I can do this? I looked through the chef code and see
theres a get_filename method as part of the cookbook code, is this
usable from within cookbooks and if so can someone point to an example
of how it would be used?

Thanks,
It might be better to know exactly what you're trying to accomplish in
context. You're going to run into lazy cookbook loading issues almost
right away and in general the solution you're heading towards is likely
to be fairly brittle. There might be a better way to solve the bigger
problem that you're trying to solve that doesn't go down this hole. And
if there isn't a better way to solve the bigger problem then there might
be better helper methods to engineer and give to you to make it easier
to do things like this...

I was thinking about how I could detect if a required file was bundled
with the cookbook under cookbook/files/{default,,} or
otherwise fallback to trying to download it from a remote source.

In terms of a particular package I wanted to be able to see if the node
compatible installer was already in cookbookfiles/* (as some of my
customers like bundling packages in with the cookbook in cases where
external net access on box isnt available) and get its path to use as a
source for the package resource. I figured get_filename would be able to
give me that path if it existed but not sure.

After thinking about it more (given that its not a good idea to put
large files in git anyway), im thinking of just doing this all through
attributes instead and force providing a source path in the case of
local files (not caring about how to actually get them onto the server
for now unless they provide a remote_file compatible source url).

On 05/02/2014 04:27 PM, Lamont Granquist wrote:

On 5/2/14, 9:20 AM, Julio Lajara wrote:

Hi all, I need to determine if a file is included/exists in the
files/* subdir under any appropriate folder for the current node, is
there any way I can do this? I looked through the chef code and see
theres a get_filename method as part of the cookbook code, is this
usable from within cookbooks and if so can someone point to an
example of how it would be used?

Thanks,
It might be better to know exactly what you're trying to accomplish in
context. You're going to run into lazy cookbook loading issues almost
right away and in general the solution you're heading towards is
likely to be fairly brittle. There might be a better way to solve the
bigger problem that you're trying to solve that doesn't go down this
hole. And if there isn't a better way to solve the bigger problem
then there might be better helper methods to engineer and give to you
to make it easier to do things like this...