- From: Noah Kantrowitz <
>
- To:
- Subject: [chef] Re: Re: Re: Re: Using variables to define attributes?
- Date: Mon, 6 Jul 2015 17:29:54 -0700
If var == 'myhappyhost', those two are equivalent. Most likely some
intermediary value is not what you expect. Add some logging to your recipe
code:
var = node['hostname']
Chef::Log.info("var = #{var.inspect}")
node['ec2']['instances'][var]....
Don't forget to add `-l info` to the client command line too so it will
display the logging output.
--Noah
On Jul 6, 2015, at 5:19 PM, Dan-Joe Lopez
<
>
wrote:
>
Thanks for the quick reply Noah. Unfortunately I don’t have a solid answer
>
to your question. I am working within an infrastructure that I did not
>
create. I am not sure what information that I can share with you beyond
>
the below that you might find helpful.
>
>
As far as access to other instances information; we have collections of
>
instances organized into projects. Each project contains a bunch of
>
attributes from all of its instances, so that any instance can see them.
>
>
As far as the data not being stored correctly, would that still be a
>
concern, given that manually calling the attribute works as expected when
>
call like this:
>
node[‘ec2’][‘instances’][‘myhappyhost’][‘ip’]
>
but fails when using the a var in place of the actual hostname:
>
node[‘ec2’][‘instances’][var][‘ip’]
>
?
>
>
Thanks,
>
Dan-Joe Lopez
>
Sent from Windows Mail
>
>
From: Noah Kantrowitz
>
Sent: Monday, July 6, 2015 5:03 PM
>
To:
>
>
>
>
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.