[chef] Re: defining a global variable to avoid sprinkles


Chronological Thread 
  • From:
  • To:
  • Subject: [chef] Re: defining a global variable to avoid sprinkles
  • Date: Mon, 9 Jan 2012 15:23:48 -0800

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.

§