Hi,

I did some basic googling, but didn't find an answer yet. I am sorry if
this is a FAQ.

In a manifest for creating an Apache config file, I define a hash like this:

    $aliases = {
        '/foo/'     => '/home/foo/www/',
        '/bar/'     => '/home/bar/www/',
        '/baz/'     => '/home/baz/www//'
    }

Then, in a template, I have:

    <% aliases.each_pair do |key, val| -%>
        Alias <%= key %>     <%= val %>
    <% end -%>

The result is mostly what I expect, but every once in a while, the order
in which the Aliases are generated from the 'each_pair' loop changes,
resulting in a different file.

The Ruby docs state that "hashes enumerate their values in the order that
the corresponding keys were inserted.", but is that not true for Puppet
hashes?

I did stumble across this post:

http://serverfault.com/questions/368784/puppet-and-templates-how-to-loop-sequently-and-not-randomly

which suggests to do something like

    <% aliases.sort_by {|key, value| key}.each_pair do |key, val| -%>
    <% end -%>

Will it work? Is that a proper solution?

Thanks!
Martijn Grendelman

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to