Passing attributes to recipes

Hello,

I’m relatively new to chef and I try to figure out, how to pass variable attributes like build file names or build numbers to chef recipes. So the best would be if I could add/overwrite a given attribute in a role/environment by it to knife via command line like: knife environment edit [env_name] “attribute_key=attribute_value”.

Is there a recommended way of doing that?

Thanks in advance,
Steffen

[cid:image001.png@01CCE75A.6C104420]

Steffen Fricke
Software QE Developer

Adobe Systems Engineering GmbH

49.40.3063.6454

stfricke@adobe.com

Grosse Elbstr. 27
22767 Hamburg, Germany
www.adobe.com

Registergericht: Hamburg HRB 745 37
Geschäftsführer: Michael D. Jamrosy, Thomas Mührke, Joseph J. Nemeth Jr., Richard T. Rowley

Of course you can override attributes per role/environment.
http://wiki.opscode.com/display/chef/Environments
http://wiki.opscode.com/display/chef/Roles

there are sever ways to manage those things

  1. files
  2. knife
  3. chef server web ui

I prefer the first one. Because all your changes are being tracked by git.

Thank you,
Max

On Thu, Feb 9, 2012 at 9:41 AM, Steffen Fricke stfricke@adobe.com wrote:

Hello,****



I’m relatively new to chef and I try to figure out, how to pass variable
attributes like build file names or build numbers to chef recipes. So the
best would be if I could add/overwrite a given attribute in a
role/environment by it to knife via command line like: knife environment
edit [env_name] “attribute_key=attribute_value”.****


Is there a recommended way of doing that?****


Thanks in advance,****

Steffen****


[image: Description: adobe_logo_web]****

Steffen Fricke
Software QE Developer****

Adobe Systems Engineering GmbH****

49.40.3063.6454


stfricke@adobe.com****

Grosse Elbstr. 27
22767 Hamburg, Germany ****

www.adobe.com****



Registergericht: Hamburg HRB 745 37 ****

Geschäftsführer: Michael D. Jamrosy, Thomas Mührke, Joseph J. Nemeth Jr.,
Richard T. Rowley****





Hi Steffen,

I'm also fairly new to Chef, but I've been doing this with data bags. You
might create a data bag called "build_info", and it might contain an item
called "build01". That item would then list the file names or build
numbers that you want.

Then, in your Role, create an attribute that lists the data bag items you
want to use in your recipe:

default_attributes(
"build_items" => ['build01']
)

Then you can write your recipe to search for those data bags and read your
information from there. Then, in the future, you just create new data bags
and roles for nodes that need different info.

In your recipe:

node['build_items].each do |item_name|
search(:build_info, "id:#{item_name}") do |build|
# Depending on what your data bag looks like you might
# reference something like build["filename"] or build["number"]
end
end

Hope that helps.

On Thu, Feb 9, 2012 at 11:41 AM, Steffen Fricke stfricke@adobe.com wrote:

Hello,****



I’m relatively new to chef and I try to figure out, how to pass variable
attributes like build file names or build numbers to chef recipes. So the
best would be if I could add/overwrite a given attribute in a
role/environment by it to knife via command line like: knife environment
edit [env_name] “attribute_key=attribute_value”.****


Is there a recommended way of doing that?****


Thanks in advance,****

Steffen****


[image: Description: adobe_logo_web]****

Steffen Fricke
Software QE Developer****

Adobe Systems Engineering GmbH****

49.40.3063.6454


stfricke@adobe.com****

Grosse Elbstr. 27
22767 Hamburg, Germany ****

www.adobe.com****



Registergericht: Hamburg HRB 745 37 ****

Geschäftsführer: Michael D. Jamrosy, Thomas Mührke, Joseph J. Nemeth Jr.,
Richard T. Rowley****





On Feb 9, 2012, at 12:08 PM, Brad Montgomery wrote:

I'm also fairly new to Chef, but I've been doing this with data bags. You might create a data bag called "build_info", and it might contain an item called "build01". That item would then list the file names or build numbers that you want.

One thing to be careful about is that data bags do not handle multiple writers well. If you have multiple processes writing to the same data bag at the same time, you can get data loss or corruption. So long as you ensure that you only ever have a single process that is writing to a data bag at any one point in time, you should be fine.

--
Brad Knowles bknowles@ihiji.com
SAGE Level IV, Chef Level 0.0.1

On Thu, Feb 9, 2012 at 12:12 PM, Brad Knowles bknowles@ihiji.com wrote:

One thing to be careful about is that data bags do not handle multiple writers well. If you have multiple processes writing to the same data bag at the same time, you can get data loss or corruption. So long as you ensure that you only ever have a single process that is writing to a data bag at any one point in time, you should be fine.

This has been the case for me, but that's good to know! Thanks.

--
Brad Knowles bknowles@ihiji.com
SAGE Level IV, Chef Level 0.0.1

Hi Max,

What do you use for upload the environment with the files method?
I tried as the wiki says but 'rake install' doesn't look for the
environments. Actually, I was checking the code (chef/tasks/chef_repo.rake)
and it doesn't do anything with environments...

I tried with 'knife environment from file entiroments/new_env.rb' and work
perfect, but it doesn't need to be tracked by git at your repo so is up to
you to track it.

Did I miss something?

Thanks :slight_smile:

On Thu, Feb 9, 2012 at 5:48 PM, Max Gorbul max@gorbul.net wrote:

Of course you can override attributes per role/environment.
http://wiki.opscode.com/display/chef/Environments
http://wiki.opscode.com/display/chef/Roles

there are sever ways to manage those things

  1. files
  2. knife
  3. chef server web ui

I prefer the first one. Because all your changes are being tracked by git.

Thank you,
Max

On Thu, Feb 9, 2012 at 9:41 AM, Steffen Fricke stfricke@adobe.com wrote:

Hello,****



I’m relatively new to chef and I try to figure out, how to pass variable
attributes like build file names or build numbers to chef recipes. So the
best would be if I could add/overwrite a given attribute in a
role/environment by it to knife via command line like: knife environment
edit [env_name] “attribute_key=attribute_value”.****


Is there a recommended way of doing that?****


Thanks in advance,****

Steffen****


[image: Description: adobe_logo_web]****

Steffen Fricke
Software QE Developer****

Adobe Systems Engineering GmbH****

49.40.3063.6454


stfricke@adobe.com****

Grosse Elbstr. 27
22767 Hamburg, Germany ****

www.adobe.com****



Registergericht: Hamburg HRB 745 37 ****

Geschäftsführer: Michael D. Jamrosy, Thomas Mührke, Joseph J. Nemeth
Jr., Richard T. Rowley****





--
Juanje

I use "knife from file .<(rb|json)>"

example:
knife role from file my-awesome-role.rb
knife environment from file production.rb
knife data bag from file usesr max.json

I have never used rake tasks you mentioned.

--max

2012/2/10 Juan Jesús Ojeda Croissier juanje.ojeda@gmail.com

Hi Max,

What do you use for upload the environment with the files method?
I tried as the wiki says but 'rake install' doesn't look for the
environments. Actually, I was checking the code (chef/tasks/chef_repo.rake)
and it doesn't do anything with environments...

I tried with 'knife environment from file entiroments/new_env.rb' and work
perfect, but it doesn't need to be tracked by git at your repo so is up to
you to track it.

Did I miss something?

Thanks :slight_smile:

On Thu, Feb 9, 2012 at 5:48 PM, Max Gorbul max@gorbul.net wrote:

Of course you can override attributes per role/environment.
http://wiki.opscode.com/display/chef/Environments
http://wiki.opscode.com/display/chef/Roles

there are sever ways to manage those things

  1. files
  2. knife
  3. chef server web ui

I prefer the first one. Because all your changes are being tracked by git.

Thank you,
Max

On Thu, Feb 9, 2012 at 9:41 AM, Steffen Fricke stfricke@adobe.comwrote:

Hello,****



I’m relatively new to chef and I try to figure out, how to pass variable
attributes like build file names or build numbers to chef recipes. So the
best would be if I could add/overwrite a given attribute in a
role/environment by it to knife via command line like: knife environment
edit [env_name] “attribute_key=attribute_value”.****


Is there a recommended way of doing that?****


Thanks in advance,****

Steffen****


[image: Description: adobe_logo_web]****

Steffen Fricke
Software QE Developer****

Adobe Systems Engineering GmbH****

49.40.3063.6454


stfricke@adobe.com****

Grosse Elbstr. 27
22767 Hamburg, Germany ****

www.adobe.com****



Registergericht: Hamburg HRB 745 37 ****

Geschäftsführer: Michael D. Jamrosy, Thomas Mührke, Joseph J. Nemeth
Jr., Richard T. Rowley****





--
Juanje

and yes I have all my files in git repo.

On Fri, Feb 10, 2012 at 5:11 PM, Max Gorbul max@gorbul.net wrote:

I use "knife from file .<(rb|json)>"

example:
knife role from file my-awesome-role.rb
knife environment from file production.rb
knife data bag from file usesr max.json

I have never used rake tasks you mentioned.

--max

2012/2/10 Juan Jesús Ojeda Croissier juanje.ojeda@gmail.com

Hi Max,

What do you use for upload the environment with the files method?
I tried as the wiki says but 'rake install' doesn't look for the
environments. Actually, I was checking the code (chef/tasks/chef_repo.rake)
and it doesn't do anything with environments...

I tried with 'knife environment from file entiroments/new_env.rb' and
work perfect, but it doesn't need to be tracked by git at your repo so is
up to you to track it.

Did I miss something?

Thanks :slight_smile:

On Thu, Feb 9, 2012 at 5:48 PM, Max Gorbul max@gorbul.net wrote:

Of course you can override attributes per role/environment.
http://wiki.opscode.com/display/chef/Environments
http://wiki.opscode.com/display/chef/Roles

there are sever ways to manage those things

  1. files
  2. knife
  3. chef server web ui

I prefer the first one. Because all your changes are being tracked by
git.

Thank you,
Max

On Thu, Feb 9, 2012 at 9:41 AM, Steffen Fricke stfricke@adobe.comwrote:

Hello,****



I’m relatively new to chef and I try to figure out, how to pass
variable attributes like build file names or build numbers to chef recipes.
So the best would be if I could add/overwrite a given attribute in a
role/environment by it to knife via command line like: knife environment
edit [env_name] “attribute_key=attribute_value”.****


Is there a recommended way of doing that?****


Thanks in advance,****

Steffen****


[image: Description: adobe_logo_web]****

Steffen Fricke
Software QE Developer****

Adobe Systems Engineering GmbH****

49.40.3063.6454


stfricke@adobe.com****

Grosse Elbstr. 27
22767 Hamburg, Germany ****

www.adobe.com****



Registergericht: Hamburg HRB 745 37 ****

Geschäftsführer: Michael D. Jamrosy, Thomas Mührke, Joseph J. Nemeth
Jr., Richard T. Rowley****





--
Juanje

Aha...

I imagined that. I ask you because what the wiki says as a 'file' method
seems to suggest that you can do it by using 'rake install':

"""
The Ruby DSL

Environments created through this mechanism get compiled to JSON, and then
are loaded in to the Chef Server. (We never execute ruby code directly on
the chef server!) Each time you rake
installhttp://wiki.opscode.com/display/chef/Chef+Repository#ChefRepository-InstallthelatestCookbooks
your Chef Repository http://wiki.opscode.com/display/chef/Chef+Repository,
we will re-compile the corresponding JSON and store it in the chef server.

You should create these files in the 'environments' subdirectory of your
chef repository. If your repository doesn't have this directory, create it
now. Each DSL file should have a .rb suffix.

...
"""

I think it should be more clear (or add the task to the Rake...) at the
wiki.

On Sat, Feb 11, 2012 at 1:11 AM, Max Gorbul max@gorbul.net wrote:

I use "knife from file .<(rb|json)>"

example:
knife role from file my-awesome-role.rb
knife environment from file production.rb
knife data bag from file usesr max.json

I have never used rake tasks you mentioned.

--max

2012/2/10 Juan Jesús Ojeda Croissier juanje.ojeda@gmail.com

Hi Max,

What do you use for upload the environment with the files method?
I tried as the wiki says but 'rake install' doesn't look for the
environments. Actually, I was checking the code (chef/tasks/chef_repo.rake)
and it doesn't do anything with environments...

I tried with 'knife environment from file entiroments/new_env.rb' and
work perfect, but it doesn't need to be tracked by git at your repo so is
up to you to track it.

Did I miss something?

Thanks :slight_smile:

On Thu, Feb 9, 2012 at 5:48 PM, Max Gorbul max@gorbul.net wrote:

Of course you can override attributes per role/environment.
http://wiki.opscode.com/display/chef/Environments
http://wiki.opscode.com/display/chef/Roles

there are sever ways to manage those things

  1. files
  2. knife
  3. chef server web ui

I prefer the first one. Because all your changes are being tracked by
git.

Thank you,
Max

On Thu, Feb 9, 2012 at 9:41 AM, Steffen Fricke stfricke@adobe.comwrote:

Hello,****



I’m relatively new to chef and I try to figure out, how to pass
variable attributes like build file names or build numbers to chef recipes.
So the best would be if I could add/overwrite a given attribute in a
role/environment by it to knife via command line like: knife environment
edit [env_name] “attribute_key=attribute_value”.****


Is there a recommended way of doing that?****


Thanks in advance,****

Steffen****


[image: Description: adobe_logo_web]****

Steffen Fricke
Software QE Developer****

Adobe Systems Engineering GmbH****

49.40.3063.6454


stfricke@adobe.com****

Grosse Elbstr. 27
22767 Hamburg, Germany ****

www.adobe.com****



Registergericht: Hamburg HRB 745 37 ****

Geschäftsführer: Michael D. Jamrosy, Thomas Mührke, Joseph J. Nemeth
Jr., Richard T. Rowley****





--
Juanje

--
Juanje