[chef] Re: Using variables to define attributes?


Chronological Thread 
  • From: Dan-Joe Lopez < >
  • To: " " < >
  • Subject: [chef] Re: Using variables to define attributes?
  • Date: Mon, 6 Jul 2015 23:53:22 +0000
  • Accept-language: en-US
  • Authentication-results: lists.opscode.com; dkim=none (message not signed) header.d=none;

OHAI Chefs!

I don’t know if this is even possible, but I am starting to feel like it is not ☹ Also, I am pretty green, so my advanced apologies if this is a silly question.

I would like to call a specific attribute by using a variable, or another attribute.  I cannot find any documentation on the subject, and every method that I have tried has resulted in an error.

So, I can call node[‘hostname’] and get the hostname; not a problem.
But then let’s say I want to write something that calls an attribute in which the host name is one of the path components… e.g.
node[‘ec2’][‘instances’][HOSTNAME][‘ip’]…

if I manually type in the host name, no problem:
node[‘ec2’][‘instances’][‘myhappyhost’][‘ip’]
BOOM: 12.34.56.78

but when I try any variation of:
node[‘ec2’][‘instances’][node[‘hostname’]][‘ip’]
or
var = node[‘hostname’]
node[‘ec2’][‘instances’][var][‘ip’]
node[‘ec2’][‘instances’][“var”][‘ip’]
node[‘ec2’][‘instances’][‘var’][‘ip’]
node[‘ec2’][‘instances’].var[‘ip’]
etc…

nothing but errors ☹

Am I missing a permutation of syntax here? Is there documentation that would have given me the answer? Is this even possible?

Your suggestions and help are appreciated!

Regards,
Dan-Joe Lopez


Sent from Windows Mail




Archive powered by MHonArc 2.6.16.

§