Fix an error on empty list from chef search
Change-Id: Iacfd5614849b3885c5be833122d1f640c34ce66c
This commit is contained in:
parent
0799cbabff
commit
305f84685d
@ -27,10 +27,15 @@ def node_election(role, tag, chef_environment = nil)
|
||||
nodes = search(:node, "run_list:role\\[#{role}\\] AND \
|
||||
chef_environment:#{chef_environment}") || []
|
||||
nodes = nodes.sort_by { |node| node.name } unless nodes.empty?
|
||||
if node.name.eql?(nodes.first.name)
|
||||
if nodes.empty? or node.name.eql?(nodes.first.name)
|
||||
node.tags << tag unless node.tags.include?(tag)
|
||||
node.save
|
||||
end
|
||||
|
||||
if nodes.empty?
|
||||
return node
|
||||
end
|
||||
|
||||
return nodes.first
|
||||
else
|
||||
return master.first
|
||||
|
Loading…
x
Reference in New Issue
Block a user