[chef] Re: Re: Re: Re: Environment - No resource or method named `template'


Chronological Thread 
  • From: Douglas Garstang < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: Environment - No resource or method named `template'
  • Date: Fri, 14 Feb 2014 13:41:56 -0800

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 < " target="_blank"> > 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: https://github.com/sethvargo/chef-sugar#node

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 < "> (mailto: "> )> 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: "> (mailto: "> )
> Cell: +1-805-340-5627






--
Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang
Email: ">
Cell: +1-805-340-5627



Archive powered by MHonArc 2.6.16.

§