- From: AJ Christensen <
>
- To:
- Subject: [chef] Re: Re: defining a global variable to avoid sprinkles
- Date: Tue, 10 Jan 2012 12:50:11 +1300
search doesn't work in attributes. you don't need to store the result
of the search in an attribute. do it in a recipe and stuff it in a
local var
wildcards and stuff are available, it's standard lucene with some
additions; I'm sure they are covered on the wiki.
Cheers,
--AJ
On 10 January 2012 12:23,
<
>
wrote:
>
On Tue, 10 Jan 2012, AJ Christensen wrote:
>
>
> Hey hey,
>
>
hey, thanks for the additional info. after i succeed with this
>
exercise, i think i'll move on to using a data bag for this. but,
>
>
i'm having trouble with rendering the search results. can ya help?
>
i figure it's something silly i'm just not seeing.
>
>
let's say i'm looking for this rendered result:
>
>
smtp-foo = admin1.dev.abfabreunion.com
>
>
if i use this in my attributes:
>
>
mrepo_smtpserver = search("node", "role:#{node['postfix-server']} AND
>
ec2_placement_availability_zone:us-east-1b AND
>
chef_environment:#{node.chef_environment}")
>
default[:mrepo][:smtpserverfoo] = "#{mrepo_smtpserver}"
>
>
the template contains:
>
smtp-foo = <%= node[:mrepo][:smtpserverfoo] %>
>
>
the rendered config file is:
>
>
[admin]# grep smtp-foo /etc/mrepo.conf
>
smtp-foo = noderole: AND ec2_placement_availability_zone:us-east-1b AND
>
chef_environment:dev
>
>
that's wrong..
>
>
i also used the syntax from your example, but the result in the rendered
>
template was the same wrongness:
>
mrepo_smtpserver = search(:node, "role:postfix-server AND
>
ec2_placement_availability_zone:us-east-1 AND
>
chef_enviornment:#{node.chef_environment}")
>
>
result:
>
smtp-foo = noderole:postfix-server AND
>
ec2_placement_availability_zone:us-east-1 AND chef_enviornment:dev
>
>
>
illustrations and more questions:
>
>
[chef-repo]$ knife search node 'role:postfix-server' -i
>
4 items found
>
admin2.dev.abfabreunion.com
>
admin1.prod.abfabreunion.com
>
admin1.dev.abfabreunion.com
>
admin2.prod.abfabreunion.com
>
>
i'm not sure what the difference is between these 2 invocations, but for
>
fun:
>
>
[chef-repo]$ knife exec -E 'nodes.search("role:postfix-server") { |n| puts
>
n.fqdn }'
>
admin2.dev.abfabreunion.com
>
admin1.dev.abfabreunion.com
>
admin1.prod.abfabreunion.com
>
admin2.prod.abfabreunion.com
>
>
>
[chef-repo]$ knife search node "ec2_placement_availability_zone:us-east-1b
>
AND role:postfix-server"| grep ^Node
>
Node Name: admin1.dev.abfabreunion.com
>
Node Name: admin2.prod.abfabreunion.com
>
>
so, the data is available for me to grab via search..
>
>
as an aside, in the plethora of cookbook examples i'm combing thru, i
>
notice places where ".first" is appended. i wonder if that's like "head
>
-1" .. take the first one from the list. i wonder if i'll need that
>
since i have multiple nodes of role:postfix-server.
>
>
an additional question -- in the search syntax in the attributes, how
>
would i match on "us-east-1" for ec2_placement_availability_zone?
>
available are us-east-1a, 1b, 1c.. maybe i'll see that a wildcard match
>
will work as soon as i get some basic rendering to succeed.
>
>
>
ok yay. thanks!
>
kallen
>
Archive powered by MHonArc 2.6.16.