[chef] Re: *** PROBABLY SPAM *** detecting a node's role, acting on it, throws exception


Chronological Thread 
  • From: Tensibai < >
  • To: < >
  • Subject: [chef] Re: *** PROBABLY SPAM *** detecting a node's role, acting on it, throws exception
  • Date: Fri, 03 Feb 2012 11:07:38 +0100

Le 02.02.2012 04:10, 

 a écrit :

hello,

Hello


regardless of the style of userdata we pass in at launch time, that
userdata is in the node attribute data in chef, be it at the top level
under normal attr data or under [:ec2][:userdata]. so i figured i could
test for the values in node attr data in my recipe. but the way i'm
trying it is throwing an exception on legacy hosts for this line in
the recipe:

if node[:ec2][:userdata] =~ /-r admin/ || node[:wewt][:role] == "admin"


Indeed trying to call [:role] on something not existing at all ( the [:wewt] part on "legagy" hosts ) throw an execption:

I'd probably write your test like this:

admorapp = "no"

if node[:ec2]
  if node[:ec2][:userdata] =~ /-r admin/
    admorapp = "admin"
  elsif node[:ec2][:userdata] =~ /-r app/
    admorapp ="app"
  end
elsif node[:wewt]
  if node[:wewt][:role] == "admin"
    admorapp = "admin"
  elsif node[:wewt][:role] == "app"
    admorapp = "app"
  end
end

Chef::Log.debug("HIGGS-BOSON: #{admorapp} role detected")


You may add a if to check if role is detected or not checking admorapp == "no" to throw a message/do something if no role is detected ...







Archive powered by MHonArc 2.6.16.

§