Hello All, I''ve run into an issue where an array that''s being passed into a defined type is being "flattened" when it''s inclosed in double quotes and I''m not sure how to get around this. This is happening a the pdxcat/amanda module and I''ve raised an github issues for this but wanted to query the community as a whole. The issue and my branch of the code are below. The amanda::server or amanda::configs class/defined type allow you to populate amanda configuration directories from files, /etc/amanda/$configs, by setting configs => [ "daily", "weekly" ] in the manifest. In my defined type, amanda::disklist, the parameter $configs needs to be used to set the correct target path to a file which I''m using contact::fragment to modify. When $configs is a single value, say "daily", everything works as expected. But then $configs is an array, "daily" and "weekly", it''s flattened to "dailyweekly" which results in an "Invalid relationship:" error. Can anyone provide some guidance on how to get around this? I''ve been banging on this for a few days and my heads really starting to hurt. define amanda::disklist ( $configs, $diskdevice = undef, $dumptype, $ensure = present, $interface = undef, $order = 20, $spindle = undef ) { include amanda::params include amanda::virtual concat::fragment { "amanda::disklist/$title": target => "$amanda::params::configs_directory/$configs/disklist", ensure => $ensure, order => $order, content => "$fqdn $name $diskdevice $dumptype $spindle $interface\n", tag => "amanda_dle", } https://github.com/pdxcat/puppet-module-amanda/issues/12 https://github.com/deadpoint/puppet-amanda/tree/disklist -- Later, Darin -- 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. For more options, visit https://groups.google.com/groups/opt_out.
On 9/19/13 4:13 PM, Darin Perusich wrote:> Hello All, > > I''ve run into an issue where an array that''s being passed into a > defined type is being "flattened" when it''s inclosed in double quotes > and I''m not sure how to get around this. This is happening a the > pdxcat/amanda module and I''ve raised an github issues for this but > wanted to query the community as a whole. The issue and my branch of > the code are below. > > The amanda::server or amanda::configs class/defined type allow you to > populate amanda configuration directories from files, > /etc/amanda/$configs, by setting configs => [ "daily", "weekly" ] in > the manifest. In my defined type, amanda::disklist, the parameter > $configs needs to be used to set the correct target path to a file > which I''m using contact::fragment to modify. When $configs is a single > value, say "daily", everything works as expected. But then $configs is > an array, "daily" and "weekly", it''s flattened to "dailyweekly" which > results in an "Invalid relationship:" error. > > Can anyone provide some guidance on how to get around this? I''ve been > banging on this for a few days and my heads really starting to hurt. > > define amanda::disklist ( > $configs, > $diskdevice = undef, > $dumptype, > $ensure = present, > $interface = undef, > $order = 20, > $spindle = undef > ) { > include amanda::params > include amanda::virtual > > concat::fragment { "amanda::disklist/$title": > target => "$amanda::params::configs_directory/$configs/disklist", > ensure => $ensure, > order => $order, > content => "$fqdn $name $diskdevice $dumptype $spindle $interface\n", > tag => "amanda_dle", > } > > https://github.com/pdxcat/puppet-module-amanda/issues/12 > https://github.com/deadpoint/puppet-amanda/tree/disklist > > -- > Later, > Darin >This is an issue with type casting. The target parameter[1] is using a string and I think that you believe that multiple concat::fragments should get called, one for each element in the array, which is not going to happen. If that is the functionality you want, then $configs[2] should stay a string and not allow arrays. You can use create_resources()[3] to call amanda::disklist multiple times, which from your issue[4], is what I believe your intention is. Here is a gist[5] to demonstrate with YAML files that you might place in Hiera. [1] - https://github.com/deadpoint/puppet-amanda/blob/disklist/manifests/disklist.pp#L14 [2] - https://github.com/deadpoint/puppet-amanda/blob/disklist/manifests/disklist.pp#L2 [3] - http://docs.puppetlabs.com/references/latest/function.html#createresources [4] - https://github.com/pdxcat/puppet-module-amanda/issues/12 [5] - https://gist.github.com/ghoneycutt/6627040 BR, -g -- 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. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, September 19, 2013 9:13:59 AM UTC-5, Darin Perusich wrote:> > Hello All, > > I''ve run into an issue where an array that''s being passed into a > defined type is being "flattened" when it''s inclosed in double quotes > and I''m not sure how to get around this.You get around it by not referencing the variable inside double quotes. Putting the variable reference inside double quotes indicates that you want to interpolate its (one) string value into the (one) larger string.> This is happening a the > pdxcat/amanda module and I''ve raised an github issues for this but > wanted to query the community as a whole. The issue and my branch of > the code are below. > > The amanda::server or amanda::configs class/defined type allow you to > populate amanda configuration directories from files, > /etc/amanda/$configs, by setting configs => [ "daily", "weekly" ] in > the manifest. In my defined type, amanda::disklist, the parameter > $configs needs to be used to set the correct target path to a file > which I''m using contact::fragment to modify. When $configs is a single > value, say "daily", everything works as expected. But then $configs is > an array, "daily" and "weekly", it''s flattened to "dailyweekly" which > results in an "Invalid relationship:" error. >What is the desired behavior in this case? Choose the first element? The last? A random one? Perhaps do something for each element?> > Can anyone provide some guidance on how to get around this? I''ve been > banging on this for a few days and my heads really starting to hurt. > > define amanda::disklist ( > $configs, > $diskdevice = undef, > $dumptype, > $ensure = present, > $interface = undef, > $order = 20, > $spindle = undef > ) { > include amanda::params > include amanda::virtual > > concat::fragment { "amanda::disklist/$title": > target => "$amanda::params::configs_directory/$configs/disklist", > ensure => $ensure, > order => $order, > content => "$fqdn $name $diskdevice $dumptype $spindle > $interface\n", > tag => "amanda_dle", > } > > https://github.com/pdxcat/puppet-module-amanda/issues/12 > https://github.com/deadpoint/puppet-amanda/tree/disklist > >Your definition seems generally ill-conceived, or at least ill-named, in the face of a $configs variable containing multiple elements. The only sensible thing I can see in that case would be for multiple files to be managed, whereas your defined type represents only one. What is the relationship between your defined type and amanda::dle? The latter appears to be doing about the same thing, but seems to get it right. The key difference there is that amanda::dle makes use of the $configs array directly as a resource title. When an array literal or an array-valued variable is used as a resource title, it serves as shorthand for multiple resource declarations, one for each array element, all with the same parameters. This behavior is often leveraged for splitting arrays into multiple elements, just as amanda::dle does. 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 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. For more options, visit https://groups.google.com/groups/opt_out.
On Thu, Sep 19, 2013 at 3:33 PM, jcbollinger <John.Bollinger@stjude.org> wrote:> > > On Thursday, September 19, 2013 9:13:59 AM UTC-5, Darin Perusich wrote: >> >> Hello All, >> >> I''ve run into an issue where an array that''s being passed into a >> defined type is being "flattened" when it''s inclosed in double quotes >> and I''m not sure how to get around this. > > > > You get around it by not referencing the variable inside double quotes. > Putting the variable reference inside double quotes indicates that you want > to interpolate its (one) string value into the (one) larger string.Yes I''m aware.> >> >> This is happening a the >> pdxcat/amanda module and I''ve raised an github issues for this but >> wanted to query the community as a whole. The issue and my branch of >> the code are below. >> >> The amanda::server or amanda::configs class/defined type allow you to >> populate amanda configuration directories from files, >> /etc/amanda/$configs, by setting configs => [ "daily", "weekly" ] in >> the manifest. In my defined type, amanda::disklist, the parameter >> $configs needs to be used to set the correct target path to a file >> which I''m using contact::fragment to modify. When $configs is a single >> value, say "daily", everything works as expected. But then $configs is >> an array, "daily" and "weekly", it''s flattened to "dailyweekly" which >> results in an "Invalid relationship:" error. > > > > What is the desired behavior in this case? Choose the first element? The > last? A random one? Perhaps do something for each element?The desired behavior is to add/remove entries in the disklist file for each $configs specified. For example your "daily" backups might run weekdays and only do incremental dumps, but the "weekly" backups run on weekends and are archived and sent off site.> >> >> >> Can anyone provide some guidance on how to get around this? I''ve been >> banging on this for a few days and my heads really starting to hurt. >> >> define amanda::disklist ( >> $configs, >> $diskdevice = undef, >> $dumptype, >> $ensure = present, >> $interface = undef, >> $order = 20, >> $spindle = undef >> ) { >> include amanda::params >> include amanda::virtual >> >> concat::fragment { "amanda::disklist/$title": >> target => "$amanda::params::configs_directory/$configs/disklist", >> ensure => $ensure, >> order => $order, >> content => "$fqdn $name $diskdevice $dumptype $spindle >> $interface\n", >> tag => "amanda_dle", >> } >> >> https://github.com/pdxcat/puppet-module-amanda/issues/12 >> https://github.com/deadpoint/puppet-amanda/tree/disklist >> > > > Your definition seems generally ill-conceived, or at least ill-named, in the > face of a $configs variable containing multiple elements. The only sensible > thing I can see in that case would be for multiple files to be managed, > whereas your defined type represents only one.I thought about creating multiple files but values in amanda.conf are not managed by puppet, other than being copied to the server, so the admin would need to know to add/set disklist value which is typically not present. I see this as being a future enhancement to the module.> What is the relationship between your defined type and amanda::dle? The > latter appears to be doing about the same thing, but seems to get it right. > The key difference there is that amanda::dle makes use of the $configs array > directly as a resource title. When an array literal or an array-valued > variable is used as a resource title, it serves as shorthand for multiple > resource declarations, one for each array element, all with the same > parameters. This behavior is often leveraged for splitting arrays into > multiple elements, just as amanda::dle does.With amanda::dle I was trying another approach, but it causes duplicate definitions so I wouldn''t say it got it right;-) -- Later, Darin -- 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. For more options, visit https://groups.google.com/groups/opt_out.
On Thursday, September 19, 2013 3:04:45 PM UTC-5, Darin Perusich wrote:> > On Thu, Sep 19, 2013 at 3:33 PM, jcbollinger <John.Bo...@stjude.org<javascript:>> > wrote: > > > > > > On Thursday, September 19, 2013 9:13:59 AM UTC-5, Darin Perusich wrote: > >> > >> Hello All, > >> > >> I''ve run into an issue where an array that''s being passed into a > >> defined type is being "flattened" when it''s inclosed in double quotes > >> and I''m not sure how to get around this. > > > > > > > > You get around it by not referencing the variable inside double quotes. > > Putting the variable reference inside double quotes indicates that you > want > > to interpolate its (one) string value into the (one) larger string. > > Yes I''m aware. > > > > >> > >> This is happening a the > >> pdxcat/amanda module and I''ve raised an github issues for this but > >> wanted to query the community as a whole. The issue and my branch of > >> the code are below. > >> > >> The amanda::server or amanda::configs class/defined type allow you to > >> populate amanda configuration directories from files, > >> /etc/amanda/$configs, by setting configs => [ "daily", "weekly" ] in > >> the manifest. In my defined type, amanda::disklist, the parameter > >> $configs needs to be used to set the correct target path to a file > >> which I''m using contact::fragment to modify. When $configs is a single > >> value, say "daily", everything works as expected. But then $configs is > >> an array, "daily" and "weekly", it''s flattened to "dailyweekly" which > >> results in an "Invalid relationship:" error. > > > > > > > > What is the desired behavior in this case? Choose the first element? > The > > last? A random one? Perhaps do something for each element? > > The desired behavior is to add/remove entries in the disklist file for > each $configs specified. For example your "daily" backups might run > weekdays and only do incremental dumps, but the "weekly" backups run > on weekends and are archived and sent off site. > > > > >> > >> > >> Can anyone provide some guidance on how to get around this? I''ve been > >> banging on this for a few days and my heads really starting to hurt. > >> > >> define amanda::disklist ( > >> $configs, > >> $diskdevice = undef, > >> $dumptype, > >> $ensure = present, > >> $interface = undef, > >> $order = 20, > >> $spindle = undef > >> ) { > >> include amanda::params > >> include amanda::virtual > >> > >> concat::fragment { "amanda::disklist/$title": > >> target => > "$amanda::params::configs_directory/$configs/disklist", > >> ensure => $ensure, > >> order => $order, > >> content => "$fqdn $name $diskdevice $dumptype $spindle > >> $interface\n", > >> tag => "amanda_dle", > >> } > >> > >> https://github.com/pdxcat/puppet-module-amanda/issues/12 > >> https://github.com/deadpoint/puppet-amanda/tree/disklist > >> > > > > > > Your definition seems generally ill-conceived, or at least ill-named, in > the > > face of a $configs variable containing multiple elements. The only > sensible > > thing I can see in that case would be for multiple files to be managed, > > whereas your defined type represents only one. > > I thought about creating multiple files but values in amanda.conf are > not managed by puppet, other than being copied to the server, so the > admin would need to know to add/set disklist value which is typically > not present. I see this as being a future enhancement to the module. > > > What is the relationship between your defined type and amanda::dle? The > > latter appears to be doing about the same thing, but seems to get it > right. > > The key difference there is that amanda::dle makes use of the $configs > array > > directly as a resource title. When an array literal or an array-valued > > variable is used as a resource title, it serves as shorthand for > multiple > > resource declarations, one for each array element, all with the same > > parameters. This behavior is often leveraged for splitting arrays into > > multiple elements, just as amanda::dle does. > > With amanda::dle I was trying another approach, but it causes > duplicate definitions so I wouldn''t say it got it right;-) > >Ok, let''s start at the top. Writing Puppet manifests is an exercise in modeling aspects of the target node, so what (type of) aspect of the target node does your amanda::disklist definition model? It seems to be intended to model one disk device that should be declared in one *or more*disklist-type files on the target node. As such, the chosen name is misleading. Poor names confuse everyone, including sometimes the name-giver, so you really ought to rename the definition to something along the lines of amanda::disk. (Not even "dle", which I suspect is short for "disk list entry", because the definition encompasses possibly-many entries in different files.) Next, you have the issue that each disk may require entries in multiple disklist files. These must correspond to separate Concat::Fragment resources because they go into different target files, therefore they must have titles distinct from each other, and also distinct from the titles of fragments associated with any other disk. This must be where your "dle" approach ran off the rails. At minimum, then, you need to create a distinct name for each Fragment. That''s not actually such a hard problem in this case, once you discover the built-in regsubst() function. For example: $fragments = regsubst($configs, ''.*'', "${title}-\\0") should produce either a scalar or an array in $fragments, as $configs is a scalar or an array, with each element having the form <instance title>-<config> Those would probably make suitable Fragment titles, provided that $configs elements are not permitted to contain hyphens (else there is a potential for collisions). Furthermore, such titles not only uniquely identify the desired fragments, they also carry the characteristic datum for each fragment that varies between different fragments associated with the same amanda::disk. You can insert an additional definition representing an individual disklist entry that will consume such titles and declare the target fragment. Thus, you might have something along these lines: define amanda::disk ( $configs, $diskdevice = undef, $dumptype, $ensure = present, $interface = undef, $order = 20, $spindle = undef ) { $entries = regsubst($configs, ''.*'', "${title}-\\0") amanda::disklist_entry { $entries: diskdevice => $diskdevice, dumptype => $dumptype, ensure => $ensure, interface => $interface, order => $order, spindle => $spindle } } amanda::disklist_entry ( $diskdevice, $dumptype, $ensure, $interface, $order, $spindle ) { include ''amanda::params'' # unpack the title $config = regsubst($title, ''^.*-'', '''') $disk = regsubst($title, ''-[^-]*$'', '''') # might want to insert some validation here ... concat::fragment { "amanda::disklist/${title}": target => "${amanda::params::configs_directory}/${config}/disklist", ensure => $ensure, order => $order, content => "${::fqdn} ${disk} ${diskdevice} ${dumptype} ${spindle} ${interface}\n", tag => "amanda_dle", } } 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 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. For more options, visit https://groups.google.com/groups/opt_out.