Using a variable populated below in a resource defined above


#1

I have a case where I assign a variable “known_nodes” in a resource but
need to use it on another resource which I’ve defined above that one, and
set the action to ‘:nothing’, and am calling it from below. This does not
work since the code is executed in order from top to bottom.

How could I do this properly? Here is the code:

TAI
cluster_name = node[“cluster_name”]
separator=","
known_nodes=self.node[‘ipaddress’]

cluster_rebal “MainCluster” do
knownNodes known_nodes
action :nothing
end

node[‘member_ips’].each do |node_name,node_ip|
if node_ip != self.node[‘ipaddress’]
known_nodes=known_nodes+separator+"#{node_ip}"
add_node “#{cluster_name}” do
hostname node_ip
notifies :rebalance, “cluster_rebal[MainCluster]”, :immediately
end
end
end


#2

Try this:

notifies :run, resources(:execute => “cluster_rebal[MainCluster])”, :immediately

Bruce Davis
bdavis2-consultant@scholastic.com

From: Chaim Keren-Tzion <chaim@intercomp.co.ilmailto:chaim@intercomp.co.il>
Reply-To: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Date: Sunday, August 25, 2013 11:47 AM
To: chef <chef@lists.opscode.commailto:chef@lists.opscode.com>
Subject: [chef] Using a variable populated below in a resource defined above

I have a case where I assign a variable “known_nodes” in a resource but need to use it on another resource which I’ve defined above that one, and set the action to ‘:nothing’, and am calling it from below. This does not work since the code is executed in order from top to bottom.

How could I do this properly? Here is the code:

TAI

cluster_name = node[“cluster_name”]
separator=","
known_nodes=self.node[‘ipaddress’]

cluster_rebal “MainCluster” do
knownNodes known_nodes
action :nothing
end

node[‘member_ips’].each do |node_name,node_ip|
if node_ip != self.node[‘ipaddress’]
known_nodes=known_nodes+separator+"#{node_ip}"
add_node “#{cluster_name}” do
hostname node_ip
notifies :rebalance, “cluster_rebal[MainCluster]”, :immediately
end
end
end