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.
An attribute is a specific detail about a node. Attributes are used by the chef-client to understand: The current state of the node. What the state of the node was at the end of the previous chef-client run.
Within the context of a provider, new_resource is the actual resource object from the recipe meaning it contains the desired state of whatever the resource is describing.
Assign Dependencies rb file for that cookbook using the depends keyword. Declaring cookbook dependencies is not required with chef-solo.
To write a Chef recipe, you need to use Ruby language. A recipe consists of resource definitions that will issue instructions to be executed on servers. For more flexibility you can include resource definitions together with Ruby code. Before we can start writing recipes, let us discuss the building blocks of a recipe.
There are two issues here, the first is more obvious that the second
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']
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With