- From: Noah Kantrowitz <
>
- To:
- Subject: [chef] Re: Re: Using variables to define attributes?
- Date: Mon, 6 Jul 2015 17:02:03 -0700
On Jul 6, 2015, at 4:53 PM, Dan-Joe Lopez
<
>
wrote:
>
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!
node['ec2']['instances'][var] is correct, however chances are you are not
storing things correctly. How are you populating that
node['ec2']['instances'] hash? Nodes cannot see the node attributes of other
nodes by default, you need to use the search API or something else to get
that data.
--Noah
Attachment:
signature.asc
Description: Message signed with OpenPGP using GPGMail
Archive powered by MHonArc 2.6.16.