[chef] Re: Programmatically discover IP address based on tag search


Chronological Thread 
  • From: Mike < >
  • To: " " < >
  • Subject: [chef] Re: Programmatically discover IP address based on tag search
  • Date: Sat, 29 Nov 2014 09:43:52 -0500

Mark,

Can you provide some output on how your search results come out? "It doesn't work" is pretty open-ended.

Inside a `chef-shell -z` session, you can actually execute the search from your recipe, so you can test the conditions of your search.

-M


    application_nodes = search(:node, "tags:#{node['memcached']['memcached_instance']} AND tags:prod")

I suspect it may have something to do with the tags that are added to those nodes, 



On Sat, Nov 29, 2014 at 9:31 AM, Mark Nichols < " target="_blank"> > wrote:
All -

I have a pair of application nodes that need to use a pair of Memcached nodes. For simplicity sake I’ll call that application nodes app1 and app2, and the Memcached nodes mem1 and mem2.

I need to open the firewall on mem1 and mem2 to allow incoming access on port 11211, therefore I want to programmatically discover the IP addresses of app1 and app2. Since this same cookbook will be used on alpha and production nodes I also need to discover the current tier.

In the code below, the memcached_instance attribute contains the same value as one of the tags on app1 and app2, e.g., “sso"


# determine if we are an alpha or production node
if node.chef_environment == "ome-alpha"
  local_environment = "alpha"
else
  local_environment = "prod"
end

# get the list of nodes...
application_nodes = search(:node, "tags:#{node['memcached']['memcached_instance']} AND tags:#{local_environment}")

application_nodes.each do |application_node|

  firewall_rule "allow application node ips"  do
    source application_node['ipaddress']
    port node['memcached']['port']
    protocol :tcp
    action :allow
    notifies :enable, 'firewall[ufw]'
  end

end

All of this looks good but it doesn’t work. My guess is that the array structure returned by my search statement is more complex than I suspect or differently structured in someway. I’ve looked at the results of the same basic command via knife (which returns the results I expect) but I can’t get this working.

What am I missing?

Thanks,
Mark




Archive powered by MHonArc 2.6.16.

§