Jay Christopherson
2013-Mar-15 00:24 UTC
[Puppet Users] randomly changing template (hiera backed)
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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Ellison Marks
2013-Mar-15 01:36 UTC
[Puppet Users] Re: randomly changing template (hiera backed)
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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Jay Christopherson
2013-Mar-15 02:52 UTC
Re: [Puppet Users] Re: randomly changing template (hiera backed)
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 <gtyaoi@gmail.com> 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 puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > 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 puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.