Get available recipes and apply them to a node

Hi again!

I want to get all available recipes and apply them to a node. How can I do
that? I tried it by loading a cookbook and accessing the recipes of that
cookbook. But it seems I can only recieve a recipes name by doing so - but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i’m using chef 0.7.16

Hi,
you don't need a chef::recipe - run_list is an array of strings:

-Thom

On Thu, Feb 18, 2010 at 15:50, kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How can I do
that? I tried it by loading a cookbook and accessing the recipes of that
cookbook. But it seems I can only recieve a recipes name by doing so - but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16

Hi,

thanks for that! I didn't know that run_list can deal with strings :slight_smile:
Now I got one problem left: when I try to make a POST to the server, I get
a 404-Error and I don't know why.
I'm doing a

rest.post_rest('http://localhost:4000/nodes/' + node.name, node)

Any idea why this happens?

Hi,
you don't need a chef::recipe - run_list is an array of strings:
gist:307825 · GitHub

-Thom

On Thu, Feb 18, 2010 at 15:50, kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How can I
do
that? I tried it by loading a cookbook and accessing the recipes of that
cookbook. But it seems I can only recieve a recipes name by doing so -
but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16

I think you want to to post_rest to '/nodes/', since you're creating a
new node. If you're saving an existing node,
you should put_rest to '/nodes/hostname_domain_tld' (ie, gsub(".","_") on fqdn)
-T

On Thu, Feb 18, 2010 at 17:15, Kristin Thomsen kristin@counterliero.de wrote:

Hi,

thanks for that! I didn't know that run_list can deal with strings :slight_smile:
Now I got one problem left: when I try to make a POST to the server, I get
a 404-Error and I don't know why.
I'm doing a

rest.post_rest('http://localhost:4000/nodes/' + node.name, node)

Any idea why this happens?

Hi,
you don't need a chef::recipe - run_list is an array of strings:
gist:307825 · GitHub

-Thom

On Thu, Feb 18, 2010 at 15:50, kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How can I
do
that? I tried it by loading a cookbook and accessing the recipes of that
cookbook. But it seems I can only recieve a recipes name by doing so -
but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16

I tried what you said, but the post still doesn't work. Doing

name = (node.name + '' + node[:domain]).chomp.gsub('.','')
puts name
node = chef.post_rest('/nodes/' + name , node)

I still get the error

/usr/lib/ruby/1.8/net/http.rb:2097:in error!': 404 "Not Found" (Net::HTTPServerException) from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/rest.rb:233:in run_request'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/rest.rb:95:in
`post_rest'
from foo.rb:37

I think you want to to post_rest to '/nodes/', since you're creating a
new node. If you're saving an existing node,
you should put_rest to '/nodes/hostname_domain_tld' (ie, gsub(".","_") on
fqdn)
-T

On Thu, Feb 18, 2010 at 17:15, Kristin Thomsen kristin@counterliero.de
wrote:

Hi,

thanks for that! I didn't know that run_list can deal with strings :slight_smile:
Now I got one problem left: when I try to make a POST to the server, I
get
a 404-Error and I don't know why.
I'm doing a

rest.post_rest('http://localhost:4000/nodes/' + node.name, node)

Any idea why this happens?

Hi,
you don't need a chef::recipe - run_list is an array of strings:
gist:307825 · GitHub

-Thom

On Thu, Feb 18, 2010 at 15:50, Â kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How can
I
do
that? I tried it by loading a cookbook and accessing the recipes of
that
cookbook. But it seems I can only recieve a recipes name by doing so -
but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16

Also, I tried "name = node[:fqdn].chomp.gsub(".","_")" and
"chef.post_rest('/nodes/' + name , node)", but I still get a 404...

Thom May wrote:

I think you want to to post_rest to '/nodes/', since you're creating a
new node. If you're saving an existing node,
you should put_rest to '/nodes/hostname_domain_tld' (ie, gsub(".","_") on fqdn)
-T

On Thu, Feb 18, 2010 at 17:15, Kristin Thomsen kristin@counterliero.de wrote:

Hi,

thanks for that! I didn't know that run_list can deal with strings :slight_smile:
Now I got one problem left: when I try to make a POST to the server, I get
a 404-Error and I don't know why.
I'm doing a

rest.post_rest('http://localhost:4000/nodes/' + node.name, node)

Any idea why this happens?

Hi,
you don't need a chef::recipe - run_list is an array of strings:
gist:307825 · GitHub

-Thom

On Thu, Feb 18, 2010 at 15:50, kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How can I
do
that? I tried it by loading a cookbook and accessing the recipes of that
cookbook. But it seems I can only recieve a recipes name by doing so -
but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16

Ohai there!

When POSTing to a Chef REST endpoint, you want to NOT include the
resource name. So, the full URL you POST to will be:

http://yourchefserver.example.com:4000/nodes/

Using Chef::REST, this is:

rest_object.post_rest('nodes', node_data)

If it fits your usage scenario, you might want to investigate creating
Chef::Node objects and then using the Node#save method which takes
care of all of this for you.

HTH,
Dan DeLeo

On Thu, Feb 18, 2010 at 10:41 AM, Matthias Splieth matthias@splieth.com wrote:

Also, I tried "name = node[:fqdn].chomp.gsub(".","_")" and
"chef.post_rest('/nodes/' + name , node)", but I still get a 404...

Thom May wrote:

I think you want to to post_rest to '/nodes/', since you're creating a
new node. If you're saving an existing node,
you should put_rest to '/nodes/hostname_domain_tld' (ie, gsub(".","_") on
fqdn)
-T

On Thu, Feb 18, 2010 at 17:15, Kristin Thomsen kristin@counterliero.de
wrote:

Hi,

thanks for that! I didn't know that run_list can deal with strings :slight_smile:
Now I got one problem left: when I try to make a POST to the server, I
get
a 404-Error and I don't know why.
I'm doing a

rest.post_rest('http://localhost:4000/nodes/' + node.name, node)

Any idea why this happens?

Hi,
you don't need a chef::recipe - run_list is an array of strings:
gist:307825 · GitHub

-Thom

On Thu, Feb 18, 2010 at 15:50, kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How can I
do
that? I tried it by loading a cookbook and accessing the recipes of
that
cookbook. But it seems I can only recieve a recipes name by doing so -
but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16

Note that Node#save will only work if your code is running on the chef
server. post_rest will work from anywhere.

On Thu, Feb 18, 2010 at 19:24, Daniel DeLeo dan@kallistec.com wrote:

Ohai there!

When POSTing to a Chef REST endpoint, you want to NOT include the
resource name. So, the full URL you POST to will be:

http://yourchefserver.example.com:4000/nodes/

Using Chef::REST, this is:

rest_object.post_rest('nodes', node_data)

If it fits your usage scenario, you might want to investigate creating
Chef::Node objects and then using the Node#save method which takes
care of all of this for you.

HTH,
Dan DeLeo

On Thu, Feb 18, 2010 at 10:41 AM, Matthias Splieth matthias@splieth.com wrote:

Also, I tried "name = node[:fqdn].chomp.gsub(".","_")" and
"chef.post_rest('/nodes/' + name , node)", but I still get a 404...

Thom May wrote:

I think you want to to post_rest to '/nodes/', since you're creating a
new node. If you're saving an existing node,
you should put_rest to '/nodes/hostname_domain_tld' (ie, gsub(".","_") on
fqdn)
-T

On Thu, Feb 18, 2010 at 17:15, Kristin Thomsen kristin@counterliero.de
wrote:

Hi,

thanks for that! I didn't know that run_list can deal with strings :slight_smile:
Now I got one problem left: when I try to make a POST to the server, I
get
a 404-Error and I don't know why.
I'm doing a

rest.post_rest('http://localhost:4000/nodes/' + node.name, node)

Any idea why this happens?

Hi,
you don't need a chef::recipe - run_list is an array of strings:
gist:307825 · GitHub

-Thom

On Thu, Feb 18, 2010 at 15:50, kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How can I
do
that? I tried it by loading a cookbook and accessing the recipes of
that
cookbook. But it seems I can only recieve a recipes name by doing so -
but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16

Thanks for the tips! Now it works! :slight_smile:

Note that Node#save will only work if your code is running on the chef
server. post_rest will work from anywhere.

On Thu, Feb 18, 2010 at 19:24, Daniel DeLeo dan@kallistec.com wrote:

Ohai there!

When POSTing to a Chef REST endpoint, you want to NOT include the
resource name. So, the full URL you POST to will be:

http://yourchefserver.example.com:4000/nodes/

Using Chef::REST, this is:

rest_object.post_rest('nodes', node_data)

If it fits your usage scenario, you might want to investigate creating
Chef::Node objects and then using the Node#save method which takes
care of all of this for you.

HTH,
Dan DeLeo

On Thu, Feb 18, 2010 at 10:41 AM, Matthias Splieth
matthias@splieth.com wrote:

Also, I tried "name = node[:fqdn].chomp.gsub(".","_")" and
"chef.post_rest('/nodes/' + name , node)", but I still get a 404...

Thom May wrote:

I think you want to to post_rest to '/nodes/', since you're creating a
new node. If you're saving an existing node,
you should put_rest to '/nodes/hostname_domain_tld' Â (ie,
gsub(".","_") on
fqdn)
-T

On Thu, Feb 18, 2010 at 17:15, Kristin Thomsen
kristin@counterliero.de
wrote:

Hi,

thanks for that! I didn't know that run_list can deal with strings :slight_smile:
Now I got one problem left: when I try to make a POST to the server,
I
get
a 404-Error and I don't know why.
I'm doing a

rest.post_rest('http://localhost:4000/nodes/' + node.name, node)

Any idea why this happens?

Hi,
you don't need a chef::recipe - run_list is an array of strings:
gist:307825 · GitHub

-Thom

On Thu, Feb 18, 2010 at 15:50, Â kristin@counterliero.de wrote:

Hi again!

I want to get all available recipes and apply them to a node. How
can I
do
that? I tried it by loading a cookbook and accessing the recipes of
that
cookbook. But it seems I can only recieve a recipes name by doing
so -
but I
need a Chef::Recipe for doing node.run_list << a_recipe!

Any suggestions?

PS: i'm using chef 0.7.16