I have a list of nodes returned from a chef search, which will be used to create a configuration file. These nodes need to be ordered because
To create a list of nodes sorted by attribute, you would do something like this, which sorts the nodes by their domain name:
nodes = search(:node, "fqdn:*")
nodes.sort_by!{ |n| n[:fqdn] }
To return a list of only these attributes, this could be extended with:
nodes.map!{ |n| n[:fqdn] }
On more recent versions of Chef, :filter_result
can be used to only fetch the node attributes that will be used:
nodes = search(:node, "fqdn:*", filter_result: { fqdn: [:fqdn] })
nodes.map! { |node| node[:fqdn] }
nodes.sort!