Why cant I use use an attribute as a resource name in a chef recipe?

I have this attribute defined in my default attributes file:

default['remote_machine']['user']['file_name'] = '/folder/path/file_name.html'

And I am trying to reference this attribute name in a recipe as follows:

list_of_nodes = search(:node,"name:production_* AND name:*app*")

template default['remote_machine']['user']['home']['file_name'] do #ERROR HERE
  source "file_name.html.erb"
  mode "755"
  variables(
    :list_of_ips=>list_of_nodes
  )

Trying to upload this cookbook, I get an error as:

FATAL: ArgumentError: You must supply a name when declaring a default resource

If I provide a string containing the path as the argument to the resource, it works.

Can anyone help me understand what I am missing?

Thanks.

Answers


There are two issues here, the first is more obvious that the second

setting vs accessing

When you set a node attribute, you specify the precedence level (like automatic, default, normal, and override). Typically this is done in your attribtue files.

When you access that information, it's stored on the node object, so you need to use the node key:

node['remote_machine']['user']['home']['file_name']
wrong attribute

But the real reason you're getting this error is that you are accessing an undefined attribute. You've defined remote_machine.user.file_name but you're using remote_machine.user.home.file_name


Need Your Help

ArrayList is nulled when method calls another method?

java arraylist null

I'm trying to debug pickPlayers. The list "players" is populated successfully after it adds "choice", but when "isPlaying" is called, it's null.

Why does my iPhone app's web service call fail on AT&T 4g LTE only?

ios asp.net iphone networking att

I have an iPhone application that makes a few web service calls. There are 2 calls to simple RSS feeds and then there are 2 calls made to an ASP.NET powered web service.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.