Search code examples
chef-infrachef-recipe

To append the attribute name with an input variable


I want to append the node attribute name with an input integer value.

Eg:

count=1
node["example_#{count}"]

expected value: node[example_1]

But we are getting a nil value. Please let us know the right way of appending.


Solution

  • there is a different between setting and attribute, and retrieving an attribute.

    in the snippet you shared, a node attribute is being retrieved but not assign to any other variable.

    if you would like to assign a value to a node attribute, do it as follows:

    count = 1
    node.default["example_#{count}"] = 'foo'