All, I am trying to have a unique type name be having "${username}-${dotfile}" where $dotfile is an array of filenames. This is based on the Puppet 2.7 Cookbook to manage user dotfiles and ssh keys. I opened a bug here: http://projects.puppetlabs.com/issues/15919 I have a github gist here: https://gist.github.com/3323851 Any insight would be greatly appreciated. Thanks, Ron -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/vdscS1WHcZAJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nan Liu
2012-Aug-13 18:20 UTC
Re: [Puppet Users] Possible Bug? - Array Variable + Double Quotes
On Mon, Aug 13, 2012 at 4:47 AM, Ron <ronald.valente@gmail.com> wrote:> All, I am trying to have a unique type name be having > "${username}-${dotfile}" where $dotfile is an array of filenames. > This is based on the Puppet 2.7 Cookbook to manage user dotfiles and ssh > keys. > > I opened a bug here: > http://projects.puppetlabs.com/issues/15919 > > I have a github gist here: > https://gist.github.com/3323851 > > Any insight would be greatly appreciated.Puppet notify resource converts the array to a string. It''s not that the variable isn''t an array, but you are looking at the .to_s output. The following example should demonstrate this better: var = [1, 2] notice("user-${var}") $arr = inline_template("<%= var.inspect %>") notice("user-${arr}") notice: Scope(Class[main]): user-12 notice: Scope(Class[main]): user-["1", "2"] notice: Finished catalog run in 0.04 seconds A common misconception, but most people expect in puppet string+array results in an array value with the string prefix every array element, what you get is actually string + array.to_s. I haven''t seen the cookbook recipe, but I think what you meant is something closer to this: https://gist.github.com/7860c7d8c157432381e3 The crazy parsejson (from stdlib) inline_template is just getting around inline_template returning string. That should be rewritten as a puppet function. Anyhow the manifests should give an idea what you are trying to do. Nan -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Aug-13 21:14 UTC
Re: [Puppet Users] Possible Bug? - Array Variable + Double Quotes
On Monday, August 13, 2012 1:20:27 PM UTC-5, Nan Liu wrote:> > > A common misconception, but most people expect in puppet string+array > results in an array value with the string prefix every array element, > what you get is actually string + array.to_s.Yes, we seem to have seen a lot of that around here recently. We also sometimes see the closely related mistake of using "$my_array" instead of simply $my_array. I suppose it''s a sign that there is interest in combinatorial approaches to declaring resources.> I haven''t seen the > cookbook recipe, but I think what you meant is something closer to > this: > > https://gist.github.com/7860c7d8c157432381e3 > >For cases such as this one, where decorated versions of the elements of a single array are desired, the built-in regsubst() function can do the job relatively easily. Note that the result should be assigned to a new variable, as function return values cannot directly be used as resource titles. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/W-T811RrgAYJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ron
2012-Aug-13 21:23 UTC
Re: [Puppet Users] Possible Bug? - Array Variable + Double Quotes
On Monday, August 13, 2012 5:14:46 PM UTC-4, jcbollinger wrote:> > > > On Monday, August 13, 2012 1:20:27 PM UTC-5, Nan Liu wrote: >> >> >> A common misconception, but most people expect in puppet string+array >> results in an array value with the string prefix every array element, >> what you get is actually string + array.to_s. > > > Yes, we seem to have seen a lot of that around here recently. We also > sometimes see the closely related mistake of using "$my_array" instead of > simply $my_array. I suppose it''s a sign that there is interest in > combinatorial approaches to declaring resources. >Yeah the reason I need the $name-$dotfile is to ensure they are unique. That said, without the quotes or the requirement for $name then it would work just fine as $dotfile.> > > >> I haven''t seen the >> cookbook recipe, but I think what you meant is something closer to >> this: >> >> https://gist.github.com/7860c7d8c157432381e3 >> >> > For cases such as this one, where decorated versions of the elements of a > single array are desired, the built-in regsubst() function can do the job > relatively easily. Note that the result should be assigned to a new > variable, as function return values cannot directly be used as resource > titles. > >How would I go about running a substring on something without a delimeter. Maybe I am just missing something obvious here.> > John > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ZlnIazkFUucJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ron
2012-Aug-13 21:44 UTC
Re: [Puppet Users] Possible Bug? - Array Variable + Double Quotes
HUGE Thanks to Nan Liu! Here is my updated gist on github. This is now working and in production. https://gist.github.com/3323851 Best, Ron On Monday, August 13, 2012 5:23:17 PM UTC-4, Ron wrote:> > > > On Monday, August 13, 2012 5:14:46 PM UTC-4, jcbollinger wrote: >> >> >> >> On Monday, August 13, 2012 1:20:27 PM UTC-5, Nan Liu wrote: >>> >>> >>> A common misconception, but most people expect in puppet string+array >>> results in an array value with the string prefix every array element, >>> what you get is actually string + array.to_s. >> >> >> Yes, we seem to have seen a lot of that around here recently. We also >> sometimes see the closely related mistake of using "$my_array" instead of >> simply $my_array. I suppose it''s a sign that there is interest in >> combinatorial approaches to declaring resources. >> > > Yeah the reason I need the $name-$dotfile is to ensure they are unique. > That said, without the quotes or the requirement for $name then it would > work just fine as $dotfile. > > >> >> >> >>> I haven''t seen the >>> cookbook recipe, but I think what you meant is something closer to >>> this: >>> >>> https://gist.github.com/7860c7d8c157432381e3 >>> >>> >> For cases such as this one, where decorated versions of the elements of a >> single array are desired, the built-in regsubst() function can do the job >> relatively easily. Note that the result should be assigned to a new >> variable, as function return values cannot directly be used as resource >> titles. >> >> > How would I go about running a substring on something without a delimeter. > Maybe I am just missing something obvious here. > > >> >> John >> >>-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/gWCZ2U0B_soJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Nan Liu
2012-Aug-13 22:02 UTC
Re: [Puppet Users] Possible Bug? - Array Variable + Double Quotes
On Mon, Aug 13, 2012 at 2:44 PM, Ron <ronald.valente@gmail.com> wrote:> HUGE Thanks to Nan Liu! > > Here is my updated gist on github. This is now working and in production. > https://gist.github.com/3323851Whoops, please don''t abuse inline_template despite my terrible example. John, thanks for the suggestion. The regsubst solution should work something like: $uname = ''jcb'' $var = [''a'', ''b'', ''c-d''] $exp = regsubst($var, ''^(.+)$'', "/home/${uname}/\\0", ''G'') notice($exp) Thanks, Nan -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.