Yep, a hash structure.  I didn't even think to check whether Ruby hashes
were ordered (I just assumed they would be), which should have been the
first thing to check when I noticed that my results were unordered.  Thanks
for the info!

On Thu, Mar 14, 2013 at 6:36 PM, Ellison Marks <[email protected]> wrote:

> each_pair, so that a hash structure, yes? Ruby hashes are unordered in
> 1.8. Iterating like that isn't guaranteed to be the same every time. You
> can iterate over the sorted keys, then get the params variable by lookup
> using the key.
>
> <%
> cachebins.keys.sort.each do |bin|
>   params = cachebins[bin]
> %>
> [stuff...]
> <% end -%>
>
>
> On Thursday, March 14, 2013 5:24:50 PM UTC-7, jc.listmail wrote:
>>
>> I have a template that I'm using to build Memcache configs from.  The
>> template looks like this:
>>
>> USER="memcached"
>> MAXCONN="1024"
>> OPTIONS=""
>> PIDDIR="/var/run/memcached"
>>
>> <% cachebins.each_pair do |bin, params| %>
>> <%= bin.upcase %>_PORT="<%= params['port'] %>"
>> <%= bin.upcase %>_CACHESIZE="<%= params['cachesize'] %>"
>> <%= bin.upcase %>_PIDFILE="$PIDDIR/<%= bin %>.pid"
>> <% end -%>
>>
>> The hiera config looks like this:
>>
>> memcache:
>>   default:
>>     port: 11211
>>     cachesize: 64
>>   session:
>>     port: 11212
>>     cachesize: 128
>>   menu:
>>     port: 11213
>>     cachesize: 64
>>   views:
>>     port: 11214
>>     cachesize: 64
>>   filter:
>>     port: 11215
>>     cachesize: 32
>>   users:
>>     port: 11216
>>     cachesize: 32
>>   page:
>>     port: 11217
>>     cachesize: 32
>>
>> and init.pp looks like this:
>>
>>         $cachebins = hiera('memcache')
>>
>>          file { "memcache_conf":
>>                 path => "/etc/sysconfig/memcached",
>>                 owner => root,
>>                 group => root,
>>                 mode => 644,
>>                 notify => Service["memcached"],
>>                 content => template("memcache/memcached.**conf.erb"),
>>         }
>>
>> The issue is that when the template is compiled, it periodically (and
>> randomly) gets recompiled in a different order, which causes my notify
>> statement to fire and restart memcache.
>>
>> The actual contents don't change, just the order in which the bins are
>> listed in the template.  I was expecting the layout to follow my hiera data
>> structure, but it seems to glob them in an unordered (and maybe random)
>> manner when it parses out into the template.
>>
>> Maybe I'm going about this in the wrong way in terms of importing my
>> hiera data, but is there a way I can force the template to be built in the
>> same order every time so that I don't have the file randomly updating and
>> causing a restart from my notify?
>>
>>
>>  --
> 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 post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/puppet-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to