[chef] Re: conditional in recipe to evaluate node name not working (as expected)


Chronological Thread 
  • From: Adam Mielke < >
  • To:
  • Subject: [chef] Re: conditional in recipe to evaluate node name not working (as expected)
  • Date: Thu, 14 Mar 2013 13:31:25 -0500

A quick check in shef (version 10.24) tells me that node["name"] returns nil, but node.name gives the expected result:

Ohai2u
chef > node['name']
 => nil
chef > node.name
 => "mynode"

--
Adam Mielke
System Engineer
University of Minnesota

On Thu, Mar 14, 2013 at 1:14 PM, Jeremy Koerber < " target="_blank"> > wrote:

Hi,
I’m trying to modify the community memcached recipe such that it will source one template file if the node name starts with qa, and another if the node name is anything else. But no matter what I try, the recipe seems to ignore the conditional and just goes with the “else” block. So the result is that my nodes that are named qa* are getting my production template sourced. I even tried just setting the node name conditional to the exact name of a specific node, and still that node ends up with the default template, not the QA one specified in the conditional. Here’s the conditional:

case node["name"]
when "qa*"
 template "/opt/zookeeper/conf/zk.conf" do
  source "zk.qa.conf.erb"
  owner "root"
  group "root"
  mode "0644"
 end
else
 template "/opt/zookeeper/conf/zk.conf" do
  source "zk.prod.conf.erb"
  owner "root"
  group "root"
  mode "0644"
 end
end

I also have these nodes in a separate chef environment called “qa”, but I’m not having any luck keying off that either. Any ideas? Here’s the output of a ‘knife node show’ for the node in question:

knife node show -Fj qa-memcached01-1-i-91e11be3
{
  "name": "qa-memcached01-1-i-91e11be3",
  "chef_environment": "qa",
  "run_list": [
    "role[memcached]"
  ],
  "normal": {
    "memcached": {
      "memory": "384"
    },
    "tags": [

    ]
  }
}

Thanks, Jeremy



--
Jeremy Koerber
Director - Tech Ops







Archive powered by MHonArc 2.6.16.

§