Search and order of results

Search order is inconsistent, is there a way to deal with it? I really would not care except every time chef runs it restarts perbal which is a issue.

Thank you,

Joshua

In my recipe:

search(:node, “role:WEBSERVER_ROLE”) do |n|
WEBSERVER_ROLE_host << n[‘ipaddress’]
end

search(:node, “role:APACHE_ROLE”) do |n|
APACHE_ROLE_host << n[‘ipaddress’]
end

template “/etc/perlbal/perlbal.conf” do
source "perlbal.conf.erb"
mode 0440
owner "root"
group "root"
variables(
:WEBSERVER_ROLE_host => WEBSERVER_ROLE_host,
:APACHE_ROLE_host => APACHE_ROLE_host
)
backup 1
notifies :restart, resources(:service => “perlbal”)
end

My Template:

CREATE POOL app_pool
<% @WEBSERVER_ROLE_host.each do |n| -%>
POOL app_pool ADD <%= n %>:80
<% end -%>

CREATE POOL media_pool
<% @APACHE_ROLE_host.each do |n| -%>
POOL media_pool ADD <%= n %>:80
<% end -%>

run A

CREATE POOL app_pool
POOL app_pool ADD 10.400.441.23:80 <<<< Problem forces restart
POOL app_pool ADD 10.400.441.24:80
POOL app_pool ADD 10.400.441.25:80

CREATE POOL media_pool
POOL media_pool ADD 10.400.441.27:80
POOL media_pool ADD 10.400.441.28:80
POOL media_pool ADD 10.400.441.27:80

run B 15 mintues later

CREATE POOL app_pool
POOL app_pool ADD 10.400.441.25:80 <<<< Problem forces restart
POOL app_pool ADD 10.400.441.23:80
POOL app_pool ADD 10.400.441.24:80

CREATE POOL media_pool
POOL media_pool ADD 10.400.441.28:80
POOL media_pool ADD 10.400.441.27:80
POOL media_pool ADD 10.400.441.27:80

On May 26, 2010, at 10:08 PM, Joshua Miller jassinpain@gmail.com wrote:

Search order is inconsistent, is there a way to deal with it? I really would not care except every time chef runs it restarts perbal which is a issue.

[snip]

search(:node, "role:WEBSERVER_ROLE") do |n|
WEBSERVER_ROLE_host << n['ipaddress']
end

[snip]

My Template:

CREATE POOL app_pool
<% @WEBSERVER_ROLE_host.each do |n| -%>
POOL app_pool ADD <%= n %>:80
<% end -%>

You could do something like WEBSERVER_ROLE_host.sort.each in the template to ensure that the array is sorted before you iterate over it.

-Mark

I love ridding public transportation as is give me a mental break and go duh ... .sort

template "/etc/perlbal/perlbal.conf" do
source "perlbal.conf.erb"
mode 0440
owner "root"
group "root"
variables(
:WEBSERVER_ROLE_host => WEBSERVER_ROLE_host.sort,
:APACHE_ROLE_host => APACHE_ROLE_host.sort
)
backup 1
notifies :restart, resources(:service => "perlbal")
end

On May 26, 2010, at 8:14 PM, Mark Imbriaco wrote:

On May 26, 2010, at 10:08 PM, Joshua Miller jassinpain@gmail.com wrote:

Search order is inconsistent, is there a way to deal with it? I really would not care except every time chef runs it restarts perbal which is a issue.

[snip]

search(:node, "role:WEBSERVER_ROLE") do |n|
WEBSERVER_ROLE_host << n['ipaddress']
end

[snip]

My Template:

CREATE POOL app_pool
<% @WEBSERVER_ROLE_host.each do |n| -%>
POOL app_pool ADD <%= n %>:80
<% end -%>

You could do something like WEBSERVER_ROLE_host.sort.each in the template to ensure that the array is sorted before you iterate over it.

-Mark

Don't feel bad. I just asked the same question on Chef Infra (archive) yesterday. :slight_smile:

On Wed, May 26, 2010 at 10:34 PM, Joshua Miller jassinpain@gmail.comwrote:

I love ridding public transportation as is give me a mental break and go
duh ... .sort

template "/etc/perlbal/perlbal.conf" do
source "perlbal.conf.erb"
mode 0440
owner "root"
group "root"
variables(
:WEBSERVER_ROLE_host => WEBSERVER_ROLE_host.sort,
:APACHE_ROLE_host => APACHE_ROLE_host.sort

)
backup 1
notifies :restart, resources(:service => "perlbal")

end

On May 26, 2010, at 8:14 PM, Mark Imbriaco wrote:

On May 26, 2010, at 10:08 PM, Joshua Miller jassinpain@gmail.com wrote:

Search order is inconsistent, is there a way to deal with it? I really
would not care except every time chef runs it restarts perbal which is a
issue.

[snip]

search(:node, "role:WEBSERVER_ROLE") do |n|
WEBSERVER_ROLE_host << n['ipaddress']
end

[snip]

My Template:

CREATE POOL app_pool
<% @WEBSERVER_ROLE_host.each do |n| -%>
POOL app_pool ADD <%= n %>:80
<% end -%>

You could do something like WEBSERVER_ROLE_host.sort.each in the template
to ensure that the array is sorted before you iterate over it.

-Mark

--
John Alberts