Using a file in the recipe

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]
Sent: 09 May 2014 17:58
To: 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.comhttp://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.

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 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]
Sent: 09 May 2014 17:58
To: 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

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.

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]
Sent: 04 June 2014 14:22
To: chef@lists.opscode.com
Cc: 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.commailto: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]
Sent: 09 May 2014 17:58
To: chef@lists.opscode.commailto: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.comhttp://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.