# Using a file in the recipe

**URL:** <https://discourse.chef.io/t/using-a-file-in-the-recipe/5449>\
**Category:** Chef Infra (archive)\
**Created:** [June 4, 2014, 10:24am UTC](https://discourse.chef.io/t/using-a-file-in-the-recipe/5449 "2014-06-04T10:24:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florian\_Hehlen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/florian_hehlen/32/303_2.png) [@Florian\_Hehlen](https://discourse.chef.io/u/Florian_Hehlen)\
**Post date:** [June 4, 2014, 10:24am UTC](https://discourse.chef.io/t/using-a-file-in-the-recipe/5449/1 "2014-06-04T10:24:49Z")

</div>

Hi,

I need to use a file that is delivered with a recipe. I do not need to copy it out of the cookbook. It contains some sql needed to initialize a DB.

Problem 1 - I can’t find a way to refer to a file inside a cookbook (ex: \<cookbook\_path\>/files/default/myfile.sql). I end up with something like #{Chef::Config[:file\_cache\_path]}/cookbooks/my\_cookbook/files/default/myfile.sql. It works but doesn’t feel right.

Problem 2 - I need to use the cookbook\_file resource and copy the file to tmp otherwise the file is not available locally. Again, this feels like this is not what I should be doing.

Cheers,  
Florian

From: Dennis Benzinger [[mailto:dennis.benzinger@hybris.com](mailto:dennis.benzinger@hybris.com)]  
Sent: 09 May 2014 17:58  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: who is the current user

Hello Florian,

you can use the following node attribute provided by Ohai:

node[‘current\_user’]

Cheers,  
Dennis

On 08.05.2014 09:57, Florian Hehlen wrote:  
Hi,

Is there a way to know from within a recipe the name of the user running the recipe?

Cheers,  
Florian

LEGAL DISCLAIMER  
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word “misdirected” as the subject and delete this communication from your system.

Dennis Benzinger  
Platform Automation Engineer  
Managed Services

Nymphenburger Straße 86  
80636 München, Deutschland  
[www.hybris.com](http://www.hybris.com)[http://www.hybris.com](http://www.hybris.com)

Geschäftsführer:  
Ariel Lüdi, Carsten Thoma, Moritz Zimmermann, Michael Zips

Amtsgericht:  
München, HRB 124384

LEGAL DISCLAIMER  
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word “misdirected” as the subject and delete this communication from your system.

---

<div class="post-metadata">

**Author:** ![Michael\_Glenney](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@Michael\_Glenney](https://discourse.chef.io/u/Michael_Glenney)\
**Post date:** [June 4, 2014, 12:22pm UTC](https://discourse.chef.io/t/using-a-file-in-the-recipe/5449/2 "2014-06-04T12:22:04Z")

</div>

I wouldn't do #1 just because you would have a reference to your cookbook name within a recipe in the cookbook. Not a big deal but will fail if you rename the cookbook and forget to change that.

#2 is the option I go with except I put all files like this (files needed for chef run but not for server standard ops) in {Chef::Config[:file\_cache\_path]} instead of /tmp.

MG

Sent from my iPhone

> On Jun 4, 2014, at 3:24 AM, Florian Hehlen [Florian.Hehlen@mri-group.com](mailto:Florian.Hehlen@mri-group.com) wrote:
> 
> Hi,
> 
> I need to use a file that is delivered with a recipe. I do not need to copy it out of the cookbook. It contains some sql needed to initialize a DB.
> 
> Problem 1 – I can’t find a way to refer to a file inside a cookbook (ex: \<cookbook\_path\>/files/default/myfile.sql). I end up with something like #{Chef::Config[:file\_cache\_path]}/cookbooks/my\_cookbook/files/default/myfile.sql. It works but doesn’t feel right.
> 
> Problem 2 – I need to use the cookbook\_file resource and copy the file to tmp otherwise the file is not available locally. Again, this feels like this is not what I should be doing.
> 
> Cheers,  
> Florian
> 
> From: Dennis Benzinger [[mailto:dennis.benzinger@hybris.com](mailto:dennis.benzinger@hybris.com)]  
> Sent: 09 May 2014 17:58  
> To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
> Subject: [chef] Re: who is the current user
> 
> Hello Florian,
> 
> you can use the following node attribute provided by Ohai:
> 
> node['current\_user']
> 
> Cheers,  
> Dennis
> 
> On 08.05.2014 09:57, Florian Hehlen wrote:  
> Hi,
> 
> Is there a way to know from within a recipe the name of the user running the recipe?
> 
> Cheers,  
> Florian
> 
> LEGAL DISCLAIMER  
> This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word "misdirected" as the subject and delete this communication from your system.
> 
> Dennis Benzinger  
> Platform Automation Engineer  
> Managed Services
> 
> Nymphenburger Straße 86  
> 80636 München, Deutschland  
> [www.hybris.com](http://www.hybris.com)
> 
> Geschäftsführer:  
> Ariel Lüdi, Carsten Thoma, Moritz Zimmermann, Michael Zips
> 
> Amtsgericht:  
> München, HRB 124384
> 
> LEGAL DISCLAIMER  
> This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word "misdirected" as the subject and delete this communication from your system.

---

<div class="post-metadata">

**Author:** ![Florian\_Hehlen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/florian_hehlen/32/303_2.png) [@Florian\_Hehlen](https://discourse.chef.io/u/Florian_Hehlen)\
**Post date:** [June 4, 2014, 12:49pm UTC](https://discourse.chef.io/t/using-a-file-in-the-recipe/5449/3 "2014-06-04T12:49:17Z")

</div>

Hi,

OK. So addressing files directly within the cookbook is just not possible?

It seems to me that it would be useful to have some Chef specific attributes that allow me to access them.

Something like: node[‘chef’][‘this\_cookbook’][‘files’]

Cheers,  
Florian

From: Michael Glenney [[mailto:mike.glenney@gmail.com](mailto:mike.glenney@gmail.com)]  
Sent: 04 June 2014 14:22  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Cc: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: using a file in the recipe

I wouldn’t do #1 just because you would have a reference to your cookbook name within a recipe in the cookbook. Not a big deal but will fail if you rename the cookbook and forget to change that.

#2 is the option I go with except I put all files like this (files needed for chef run but not for server standard ops) in {Chef::Config[:file\_cache\_path]} instead of /tmp.

MG

Sent from my iPhone

On Jun 4, 2014, at 3:24 AM, Florian Hehlen \<[Florian.Hehlen@mri-group.com](mailto:Florian.Hehlen@mri-group.com)[mailto:Florian.Hehlen@mri-group.com](mailto:Florian.Hehlen@mri-group.com)\> wrote:  
Hi,

I need to use a file that is delivered with a recipe. I do not need to copy it out of the cookbook. It contains some sql needed to initialize a DB.

Problem 1 – I can’t find a way to refer to a file inside a cookbook (ex: \<cookbook\_path\>/files/default/myfile.sql). I end up with something like #{Chef::Config[:file\_cache\_path]}/cookbooks/my\_cookbook/files/default/myfile.sql. It works but doesn’t feel right.

Problem 2 – I need to use the cookbook\_file resource and copy the file to tmp otherwise the file is not available locally. Again, this feels like this is not what I should be doing.

Cheers,  
Florian

From: Dennis Benzinger [[mailto:dennis.benzinger@hybris.com](mailto:dennis.benzinger@hybris.com)]  
Sent: 09 May 2014 17:58  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)[mailto:chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: who is the current user

Hello Florian,

you can use the following node attribute provided by Ohai:

node[‘current\_user’]

Cheers,  
Dennis

On 08.05.2014 09:57, Florian Hehlen wrote:  
Hi,

Is there a way to know from within a recipe the name of the user running the recipe?

Cheers,  
Florian

LEGAL DISCLAIMER  
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word “misdirected” as the subject and delete this communication from your system.

Dennis Benzinger  
Platform Automation Engineer  
Managed Services

Nymphenburger Straße 86  
80636 München, Deutschland  
[www.hybris.com](http://www.hybris.com)[http://www.hybris.com](http://www.hybris.com)

Geschäftsführer:  
Ariel Lüdi, Carsten Thoma, Moritz Zimmermann, Michael Zips

Amtsgericht:  
München, HRB 124384

LEGAL DISCLAIMER  
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word “misdirected” as the subject and delete this communication from your system.

LEGAL DISCLAIMER  
This communication and any attached documents are strictly confidential and/or legally privileged and they may not be used or disclosed by someone who is not a named recipient. If you have received this electronic communication in error please notify the sender by replying to this electronic communication inserting the word “misdirected” as the subject and delete this communication from your system.
