Issue #16266 has been updated by Sam Morrison.

For other people that find this the example fix to template syntax has a small 
bug
This one will work:

<% aliases.keys.sort.each do |key| -%>
    Alias <%= key %>     <%= aliases[key] %>
<% end -%>

----------------------------------------
Bug #16266: Hash iteration order in a template not consistent
https://projects.puppetlabs.com/issues/16266#change-98557

* Author: Mathieu Parent
* Status: Rejected
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* Affected Puppet version: 
* Keywords: 
* Branch: 
----------------------------------------
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?

Sorting the hash will allow consistent printing, but what if input order is 
preferred?

NB: This has already be mentioned at 
https://groups.google.com/forum/?fromgroups=#!topic/puppet-users/8mjAVGh8rRI


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to