Environment - No resource or method named `template'

I’ve just started trying to use environments in chef. Everything worked
find locally with vagrant, but after uploading the cookbook to the target
machine, and attempting to do a chef client run, I am seeing this error:

NoMethodError

No resource or method named template' forChef::Recipe “default”’

I have no idea what is going on here. If chef can’t find it’s own template
resource, then something is seriously wrong. This is a fresh instance.

I can confirm my environment is there…

(xxx-prod) Douglass-Mac-mini: knife-eu2 environment show eu2-prod
chef_type: environment
cookbook_versions:
default_attributes:
description:
json_class: Chef::Environment
name: eu2-prod
override_attributes:

I can also confirm that the node belongs to the environment:

(xxx-prod) Douglass-Mac-mini: knife-eu2 node show osg04-eu2.xxx.net
Node Name: osg04-eu2.xxx.net
Environment: eu2-prod
FQDN:
IP:
Run List: role[location_eu2_prod], role[role_base], role[role_osg]
Roles:
Recipes:
Platform:
Tags:

What gives?

Doug.

You’re hitting this bug: https://tickets.opscode.com/browse/CHEF-5011

Which means you have code like:

template “path” do

correct code

something_that_raises_no_method_error
end

Though this bug does not impact any correct chef code, it makes debugging difficult so we’re going to release an update to fix it soon.

--
Daniel DeLeo

On Friday, February 14, 2014 at 12:40 PM, Douglas Garstang wrote:

I've just started trying to use environments in chef. Everything worked find locally with vagrant, but after uploading the cookbook to the target machine, and attempting to do a chef client run, I am seeing this error:

NoMethodError

No resource or method named template' for Chef::Recipe "default"'

I have no idea what is going on here. If chef can't find it's own template resource, then something is seriously wrong. This is a fresh instance.

I can confirm my environment is there...

(xxx-prod) Douglass-Mac-mini: knife-eu2 environment show eu2-prod
chef_type: environment
cookbook_versions:
default_attributes:
description:
json_class: Chef::Environment
name: eu2-prod
override_attributes:

I can also confirm that the node belongs to the environment:

(xxx-prod) Douglass-Mac-mini: knife-eu2 node show osg04-eu2.xxx.net (http://osg04-eu2.xxx.net)
Node Name: osg04-eu2.xxx.net (http://osg04-eu2.xxx.net)
Environment: eu2-prod
FQDN:
IP:
Run List: role[location_eu2_prod], role[role_base], role[role_osg]
Roles:
Recipes:
Platform:
Tags:

What gives?

Doug.

Daniel.

Thanks for the reply. I took a look at the bug, and I think I see what it's
saying. However, my template code has:

template '/etc/server.yaml' do
source 'etc/server.yaml.erb'
owner 'root'
group 'root'
mode 00644
variables({
:env => node['bitcasa_env'],
:cluster => node['cluster'],
:hostname => node['hostname'],
:storage_region => node['bc-xxx-osg']['storage_region'],
:session_region => node['bc-xxx-osg']['session_region'],
:db_host => node['bc-xxx-osg']['mysql']['host'],
:redis_master => node['bc-xxx-osg']['redis']['master']['host'],
:redis_slave => node['bc-xxx-osg']['redis']['slave']['host'],
:rabbit_master => node['bc-xxx-osg']['rabbitmq']['host'],
:rabbit_port => node['bc-xxx-osg']['rabbitmq']['port']
})
end

I'm pretty sure there's no undefined methods in there. It worked fine in
vagrant. When I comment the whole thing out though, the recipe runs without
errors. It has to be somehow related to the use of environments?

Doug.

On Fri, Feb 14, 2014 at 12:45 PM, Daniel DeLeo dan@kallistec.com wrote:

You're hitting this bug: https://tickets.opscode.com/browse/CHEF-5011

Which means you have code like:

template "path" do

correct code

something_that_raises_no_method_error
end

Though this bug does not impact any correct chef code, it makes debugging
difficult so we're going to release an update to fix it soon.

--
Daniel DeLeo

On Friday, February 14, 2014 at 12:40 PM, Douglas Garstang wrote:

I've just started trying to use environments in chef. Everything worked
find locally with vagrant, but after uploading the cookbook to the target
machine, and attempting to do a chef client run, I am seeing this error:

NoMethodError

No resource or method named template' for Chef::Recipe "default"'

I have no idea what is going on here. If chef can't find it's own
template resource, then something is seriously wrong. This is a fresh
instance.

I can confirm my environment is there...

(xxx-prod) Douglass-Mac-mini: knife-eu2 environment show eu2-prod
chef_type: environment
cookbook_versions:
default_attributes:
description:
json_class: Chef::Environment
name: eu2-prod
override_attributes:

I can also confirm that the node belongs to the environment:

(xxx-prod) Douglass-Mac-mini: knife-eu2 node show osg04-eu2.xxx.net (
http://osg04-eu2.xxx.net)
Node Name: osg04-eu2.xxx.net (http://osg04-eu2.xxx.net)
Environment: eu2-prod
FQDN:
IP:
Run List: role[location_eu2_prod], role[role_base], role[role_osg]
Roles:
Recipes:
Platform:
Tags:

What gives?

Doug.

--
Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627

Probably there’s a NoMethodError in your attribute usage. If we suppose that

node[''bc-xxx-osg”][“mysql”] == nil

then

node['bc-xxx-osg']['mysql']['host’]

is the same as:

nil[“host”]

which will raise a NoMethodError because nil does not have a [] (element reference) method.

Note that I actually don’t have any idea which line is causing the error, I’m just using this as an example to illustrate.

There are ways you can expose the real error, by wrapping the code in begin; rescue; end;, like

begin

attributes code

rescue NoMethodError => e
Chef::Log.error(e)
raise
end

but you will probably find it easier to temporarily downgrade.

Another option is to use chef-sugar and then you can use the node.deep_fetch! method. See here: GitHub - sethvargo/chef-sugar

HTH,

--
Daniel DeLeo

On Friday, February 14, 2014 at 12:52 PM, Douglas Garstang wrote:

Daniel.

Thanks for the reply. I took a look at the bug, and I think I see what it's saying. However, my template code has:

template '/etc/server.yaml' do
source 'etc/server.yaml.erb'
owner 'root'
group 'root'
mode 00644
variables({
:env => node['bitcasa_env'],
:cluster => node['cluster'],
:hostname => node['hostname'],
:storage_region => node['bc-xxx-osg']['storage_region'],
:session_region => node['bc-xxx-osg']['session_region'],
:db_host => node['bc-xxx-osg']['mysql']['host'],
:redis_master => node['bc-xxx-osg']['redis']['master']['host'],
:redis_slave => node['bc-xxx-osg']['redis']['slave']['host'],
:rabbit_master => node['bc-xxx-osg']['rabbitmq']['host'],
:rabbit_port => node['bc-xxx-osg']['rabbitmq']['port']
})
end

I'm pretty sure there's no undefined methods in there. It worked fine in vagrant. When I comment the whole thing out though, the recipe runs without errors. It has to be somehow related to the use of environments?

Doug.

On Fri, Feb 14, 2014 at 12:45 PM, Daniel DeLeo <dan@kallistec.com (mailto:dan@kallistec.com)> wrote:

You’re hitting this bug: https://tickets.opscode.com/browse/CHEF-5011

Which means you have code like:

template “path” do

correct code

something_that_raises_no_method_error
end

Though this bug does not impact any correct chef code, it makes debugging difficult so we’re going to release an update to fix it soon.

--
Daniel DeLeo

On Friday, February 14, 2014 at 12:40 PM, Douglas Garstang wrote:

I've just started trying to use environments in chef. Everything worked find locally with vagrant, but after uploading the cookbook to the target machine, and attempting to do a chef client run, I am seeing this error:

NoMethodError

No resource or method named template' for Chef::Recipe "default"'

I have no idea what is going on here. If chef can't find it's own template resource, then something is seriously wrong. This is a fresh instance.

I can confirm my environment is there...

(xxx-prod) Douglass-Mac-mini: knife-eu2 environment show eu2-prod
chef_type: environment
cookbook_versions:
default_attributes:
description:
json_class: Chef::Environment
name: eu2-prod
override_attributes:

I can also confirm that the node belongs to the environment:

(xxx-prod) Douglass-Mac-mini: knife-eu2 node show osg04-eu2.xxx.net (http://osg04-eu2.xxx.net) (http://osg04-eu2.xxx.net)
Node Name: osg04-eu2.xxx.net (http://osg04-eu2.xxx.net) (http://osg04-eu2.xxx.net)
Environment: eu2-prod
FQDN:
IP:
Run List: role[location_eu2_prod], role[role_base], role[role_osg]
Roles:
Recipes:
Platform:
Tags:

What gives?

Doug.

--
Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com (mailto:doug.garstang@gmail.com)
Cell: +1-805-340-5627

Thanks Daniel. That at least helped me to work out the data from the
environment is missing. I hope that bug gets fixed soon, because having an
entire resource epically fail because one of it's variables isn't defined
isn't going to be much fun to debug.

On Fri, Feb 14, 2014 at 1:03 PM, Daniel DeLeo dan@kallistec.com wrote:

Probably there's a NoMethodError in your attribute usage. If we suppose
that

node[''bc-xxx-osg"]["mysql"] == nil

then

node['bc-xxx-osg']['mysql']['host']

is the same as:

nil["host"]

which will raise a NoMethodError because nil does not have a [] (element
reference) method.

Note that I actually don't have any idea which line is causing the error,
I'm just using this as an example to illustrate.

There are ways you can expose the real error, by wrapping the code in
begin; rescue; end;, like

begin

attributes code

rescue NoMethodError => e
Chef::Log.error(e)
raise
end

but you will probably find it easier to temporarily downgrade.

Another option is to use chef-sugar and then you can use the
node.deep_fetch! method. See here:
GitHub - sethvargo/chef-sugar

HTH,

--
Daniel DeLeo

On Friday, February 14, 2014 at 12:52 PM, Douglas Garstang wrote:

Daniel.

Thanks for the reply. I took a look at the bug, and I think I see what
it's saying. However, my template code has:

template '/etc/server.yaml' do
source 'etc/server.yaml.erb'
owner 'root'
group 'root'
mode 00644
variables({
:env => node['bitcasa_env'],
:cluster => node['cluster'],
:hostname => node['hostname'],
:storage_region => node['bc-xxx-osg']['storage_region'],
:session_region => node['bc-xxx-osg']['session_region'],
:db_host => node['bc-xxx-osg']['mysql']['host'],
:redis_master => node['bc-xxx-osg']['redis']['master']['host'],
:redis_slave => node['bc-xxx-osg']['redis']['slave']['host'],
:rabbit_master => node['bc-xxx-osg']['rabbitmq']['host'],
:rabbit_port => node['bc-xxx-osg']['rabbitmq']['port']
})
end

I'm pretty sure there's no undefined methods in there. It worked fine in
vagrant. When I comment the whole thing out though, the recipe runs without
errors. It has to be somehow related to the use of environments?

Doug.

On Fri, Feb 14, 2014 at 12:45 PM, Daniel DeLeo <dan@kallistec.com(mailto:
dan@kallistec.com)> wrote:

You're hitting this bug: https://tickets.opscode.com/browse/CHEF-5011

Which means you have code like:

template "path" do

correct code

something_that_raises_no_method_error
end

Though this bug does not impact any correct chef code, it makes
debugging difficult so we're going to release an update to fix it soon.

--
Daniel DeLeo

On Friday, February 14, 2014 at 12:40 PM, Douglas Garstang wrote:

I've just started trying to use environments in chef. Everything
worked find locally with vagrant, but after uploading the cookbook to the
target machine, and attempting to do a chef client run, I am seeing this
error:

NoMethodError

No resource or method named template' for Chef::Recipe "default"'

I have no idea what is going on here. If chef can't find it's own
template resource, then something is seriously wrong. This is a fresh
instance.

I can confirm my environment is there...

(xxx-prod) Douglass-Mac-mini: knife-eu2 environment show eu2-prod
chef_type: environment
cookbook_versions:
default_attributes:
description:
json_class: Chef::Environment
name: eu2-prod
override_attributes:

I can also confirm that the node belongs to the environment:

(xxx-prod) Douglass-Mac-mini: knife-eu2 node show osg04-eu2.xxx.net(
http://osg04-eu2.xxx.net) (http://osg04-eu2.xxx.net)
Node Name: osg04-eu2.xxx.net (http://osg04-eu2.xxx.net) (
http://osg04-eu2.xxx.net)
Environment: eu2-prod
FQDN:
IP:
Run List: role[location_eu2_prod], role[role_base], role[role_osg]
Roles:
Recipes:
Platform:
Tags:

What gives?

Doug.

--
Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com (mailto:doug.garstang@gmail.com)
Cell: +1-805-340-5627

--
Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627

On Friday, February 14, 2014 at 1:41 PM, Douglas Garstang wrote:

Thanks Daniel. That at least helped me to work out the data from the environment is missing. I hope that bug gets fixed soon, because having an entire resource epically fail because one of it's variables isn't defined isn't going to be much fun to debug.

We’re aiming for early next week. Here’s the tag for the patch release (RC): GitHub - chef/chef at 11.10.2.rc.0

There’s a little bit of a delay because we’re trying to incorporate the latest libyaml security patch. On *nix platforms this is easy but on windows we use devkit and they refuse to release new builds in response to upstream security issues: CVE-2013-6393: Libyaml heap overrun vulnerability requires new installer release · Issue #210 · oneclick/rubyinstaller · GitHub So we have a little bit of dev work to do on our build system to pull in the latest libyaml dll.

FWIW, we’re also going to release a new iteration of the latest 10.x version to include this libyaml update.

--
Daniel DeLeo

Running a trivial “hello world” recipe as chef-solo

sudo chef-solo -c solo.rb -j node.json??

This all runs on the same machine. Solo.rb points to my local cookbook subdir under ~/chef-repo; node.json is a one-liner run list of the recipe.

The recipe looks for a file in my homedir, and if not there, does :create_if_missing

Or so I wish.

It cr*ps out an undefined method on cookbook_file:

NoMethodError


undefined method `cookbook_file’ for Chef::Resource::Log

Cookbook Trace:


/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:5:in `block in from_file’

/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:3:in `from_file’

Relevant File Content:


/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:

1: # This is a Chef recipe file. It can be used to specify resources which will

2: # apply configuration to a server.

3: log “Welcome to Chef, #{node[“starter_name”]}!” do

4: level :info

5>> cookbook_file “helloworld.txt” do

6: path “/Users/rossmohan/HELLOWORLD.TXT”

7: action :create_if_missing

8: end

9: end

10: ?

cookbook_file undefined? I thought that was a built-in?

Worse, looking in /var/chef for the stacktrace, top error is CookbookNotFound.

But aye, laddie, 'tis there:

rosss-air:chef-repo rossmohan$ pwd

/Users/rossmohan/chef-repo

rosss-air:chef-repo rossmohan$ ls cookbooks

apache2 apt chefignore hellocookbook starter

rosss-air:chef-repo rossmohan$ knife cookbook list

apache2 1.8.14

apt 2.3.8

hellocookbook 0.1.0

?

Even knife sees it.

Any thoughts on what to look at next?

Thanks in advance,

-Ross

?

?
?

?

Ross,

Looks like you're trying to nest resources, cookbook_file inside of log.
You can't do that.

Check out this gist for the solution

-Nathen
@nathenharvey

On Wed, Feb 19, 2014 at 9:14 AM, Ross Mohan mohanr@five9group.com wrote:

Running a trivial "hello world" recipe as chef-solo

sudo chef-solo -c solo.rb -j node.json

This all runs on the same machine. Solo.rb points to my local cookbook
subdir under ~/chef-repo; node.json is a one-liner run list of the
recipe.

The recipe looks for a file in my homedir, and if not there, does
:create_if_missing

Or so I wish.

It cr*ps out an undefined method on cookbook_file:

NoMethodError


undefined method `cookbook_file' for Chef::Resource::Log

Cookbook Trace:


/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:5:in
`block in from_file'

/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:3:in
`from_file'

Relevant File Content:


/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:

 1:  # This is a Chef recipe file. It can be used to specify

resources which will

2: # apply configuration to a server.

3: log "Welcome to Chef, #{node["starter_name"]}!" do

4: level :info

5>> cookbook_file "helloworld.txt" do

6: path "/Users/rossmohan/HELLOWORLD.TXT"

7: action :create_if_missing

8: end

9: end

10:

cookbook_file undefined? I thought that was a built-in?

Worse, looking in /var/chef for the stacktrace, top error is
CookbookNotFound*.*

But aye, laddie, 'tis there:

rosss-air:chef-repo rossmohan$ pwd

/Users/rossmohan/chef-repo

rosss-air:chef-repo rossmohan$ ls cookbooks

apache2 apt chefignore hellocookbook starter

rosss-air:chef-repo rossmohan$ knife cookbook list

apache2 1.8.14

apt 2.3.8

hellocookbook 0.1.0

Even knife sees it.

Any thoughts on what to look at next?

Thanks in advance,

-Ross

Wow. That was fast.

rosss-air:.chef rossmohan$ sudo chef-solo -c solo.rb -j node.json

Password:

Starting Chef Client, version 11.10.2

Compiling Cookbooks…

Converging 1 resources

Recipe: hellocookbook::hellorecipe

  • cookbook_file[helloworld.txt] action create_if_missing

    • create new file /Users/rossmohan/HELLOWORLD.TXT

    • update content in file /Users/rossmohan/HELLOWORLD.TXT from none to 4ef28a

      — /Users/rossmohan/HELLOWORLD.TXT 2014-02-19 09:44:01.000000000 -0500

      +++ /tmp/.helloworld.txt20140219-26170-mpfeit 2014-02-19 09:44:01.000000000 -0500

      @@ -1 +1,4 @@

      +This is the file I put in the files/default subdir of cookbook Hellocookbook for slurping up by chef(-solo) and placement in my homedir.

      +Let’s see if it worked…

Running handlers:

Running handlers complete

Chef Client finished, 1/1 resources updated in 2.052297 seconds

I guess the prohibition on nesting execute resource blocks is inherited from Ruby.

Thank you!

I did try debugging via single-stepping chef-shell, but it gave me hours of grief on “connection refused” (regardless of firewall state)

rosss-air:.chef rossmohan$ chef-shell

loading configuration: none (standalone session)

Session type: standalone

Loading…done.

This is the chef-shell.

Chef Version: 11.10.2

http://www.opscode.com/chef

http://docs.opscode.com/

run help' for help,exit’ or ^D to quit.

Ohai2u rossmohan@rosss-air.home!

chef > cookbooks.all

[2014-02-19T10:11:42-05:00] ERROR: Connection refused connecting to https://localhost/cookbooks, retry 1/5

???

Thanks again,

Ross


From: Nathen Harvey nharvey@getchef.com
Sent: Wednesday, February 19, 2014 9:18 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Undefined Method drives Sous Chef Mad. Film at 11.

Ross,

Looks like you’re trying to nest resources, cookbook_file inside of log. You can’t do that.

Check out this gist for the solution

-Nathen
@nathenharvey

On Wed, Feb 19, 2014 at 9:14 AM, Ross Mohan <mohanr@five9group.commailto:mohanr@five9group.com> wrote:
Running a trivial “hello world” recipe as chef-solo

sudo chef-solo -c solo.rb -j node.json

This all runs on the same machine. Solo.rb points to my local cookbook subdir under ~/chef-repo; node.json is a one-liner run list of the recipe.

The recipe looks for a file in my homedir, and if not there, does :create_if_missing

Or so I wish.

It cr*ps out an undefined method on cookbook_file:

NoMethodError


undefined method `cookbook_file’ for Chef::Resource::Log

Cookbook Trace:


/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:5:in `block in from_file’

/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:3:in `from_file’

Relevant File Content:


/Users/rossmohan/chef-repo/cookbooks/hellocookbook/recipes/hellorecipe.rb:

1: # This is a Chef recipe file. It can be used to specify resources which will

2: # apply configuration to a server.

3: log “Welcome to Chef, #{node[“starter_name”]}!” do

4: level :info

5>> cookbook_file “helloworld.txt” do

6: path “/Users/rossmohan/HELLOWORLD.TXT”

7: action :create_if_missing

8: end

9: end

10:

cookbook_file undefined? I thought that was a built-in?

Worse, looking in /var/chef for the stacktrace, top error is CookbookNotFound.

But aye, laddie, 'tis there:

rosss-air:chef-repo rossmohan$ pwd

/Users/rossmohan/chef-repo

rosss-air:chef-repo rossmohan$ ls cookbooks

apache2 apt chefignore hellocookbook starter

rosss-air:chef-repo rossmohan$ knife cookbook list

apache2 1.8.14

apt 2.3.8

hellocookbook 0.1.0

Even knife sees it.

Any thoughts on what to look at next?

Thanks in advance,

-Ross

On Wed, Feb 19, 2014 at 10:11 AM, Ross Mohan mohanr@five9group.com wrote:

I did try debugging via single-stepping chef-shell, but it gave me hours of
grief on "connection refused" (regardless of firewall state)

rosss-air:.chef rossmohan$ chef-shell

chef > cookbooks.all

[2014-02-19T10:11:42-05:00] ERROR: Connection refused connecting to
https://localhost/cookbooks, retry 1/5

chef-shell in standalone mode doesn't load cookbooks.

Loading chef-shell in client mode with "chef-shell -z" is probably
what you wanted. It can take a little getting used to.

Bryan

Thanks for responding to that, Brian.

This time, interestingly enough, it fails immediately, without my ever getting a chance to query cookbooks (local or server-based):

rosss-air:.chef rossmohan$ chef-shell -z
loading configuration: /etc/chef/client.rb
Session type: client
Loading....[2014-02-19T19:06:49-05:00] ERROR: Connection refused connecting to https://localhost/nodes/rosss-air.home, retry  
1/5
..........[2014-02-19T19:06:54-05:00] ERROR: Connection refused connecting to https://localhost/nodes/rosss-air.home, retry 2/5
..........[2014-02-19T19:06:59-05:00] ERROR: Connection refused connecting to https://localhost/nodes/rosss-air.home, retry 3/5
..........[2014-02-19T19:07:04-05:00] ERROR: Connection refused connecting to https://localhost/nodes/rosss-air.home, retry 4/5
.....^C
================================================================================
Chef encountered an error attempting to load the node data for "rosss-air.home"
================================================================================

Thanks, too, for the link. I'll look into that.

Sure is a lot to get used to.

-Ross


From: Bryan McLellan btm@loftninjas.org
Sent: Wednesday, February 19, 2014 1:51 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: Undefined Method drives Sous Chef Mad. Film at 11.

On Wed, Feb 19, 2014 at 10:11 AM, Ross Mohan mohanr@five9group.com wrote:

I did try debugging via single-stepping chef-shell, but it gave me hours of
grief on "connection refused" (regardless of firewall state)

rosss-air:.chef rossmohan$ chef-shell

chef > cookbooks.all

[2014-02-19T10:11:42-05:00] ERROR: Connection refused connecting to
https://localhost/cookbooks, retry 1/5

chef-shell in standalone mode doesn't load cookbooks.

Loading chef-shell in client mode with "chef-shell -z" is probably
what you wanted. It can take a little getting used to.

Bryan