- From: Mark Nichols <
>
- To:
- Subject: [chef] Programmatically discover IP address based on tag search
- Date: Sat, 29 Nov 2014 08:31:39 -0600
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
- [chef] Programmatically discover IP address based on tag search, Mark Nichols, 11/29/2014
Archive powered by MHonArc 2.6.16.