On Wednesday, February 19, 2014 1:47:35 PM UTC-6, Andre Nathan wrote: > > Hello > > Sorry to ressurect this old thread, but I've just found this issue > upgrading from Puppet 2.7.x to Puppet 3. It's true that ruby 1.8 hash order > cannot be relied on, but it should always be the same, right? I mean, one > doesn't know which order the hash contents will be iterated on, but > whatever order ruby chooses should never change. >
The iteration order of an existing hash should not change as long as entries are neither added nor removed. *Probably*, a new hash created via the same sequence of pair insertions and deletions, using the same hash implementation, will also have the same iteration order. > > We had this working with no issues in 2.7.x and ruby 1.8, but now on > Puppet 3 we're getting random reorderings. I suspect there's a problem in > Puppet in this case. > File a ticket if you wish, but personally, I'm inclined to say that *any*reliance on iteration order of a hash is dodgy. If iteration order matters then you need to take proactive measures to ensure that you reliably get the (an) order that works for you. Puppet does not document the iteration order of its hashes, or their Ruby representation in templates, so it is irrelevant that what you were doing worked in your particular prior context. For what it's worth, I speculate that in Puppet 2.7, templates got a reference to the actual Ruby hash backing the corresponding puppet variable, whereas in Puppet 3 they get *copies*. That would allow Puppet to enforce its invariant that variables' values never change once assigned, which at one time could be broken via templates. Some reasonable implementations of hash copying could end up inserting entries into the copy in a different order than they were inserted into the original, thus giving the copy a different iteration order despite having the same contents. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/885bb434-f486-4e0d-990f-72e869b8266a%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
