Matthias Saou
2011-Jul-15 11:04 UTC
[Puppet Users] Definition parameter defaulting to the definition''s own $title?
Hi, Maybe I''m going nuts, but I could have sworn reading about a trick or new feature which allowed to have a definition parameter get a default value of the definition''s own $title (instead of having the hack around the limitation with selectors and intermediate variables later on). Basically what I want to have working is this : -8<- define foo ( $bar = $namevar ) { file { ''/tmp/foo'': content => $title } file { ''/tmp/bar'': content => $bar } } # Here I want both to contain "foo" foo { ''foo'': } # Here I want bar to contain "bar" foo { ''foo'': bar => ''bar'' } -8<- Anything I can use instead of "$bar = $namevar" to get it working? Matthias -- Clean custom Red Hat Linux rpm packages : http://freshrpms.net/ Fedora release 14 (Laughlin) - Linux kernel 2.6.35.13-91.fc14.x86_64 Load : 0.36 0.40 0.85 -- 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.
R.I.Pienaar
2011-Jul-15 11:07 UTC
Re: [Puppet Users] Definition parameter defaulting to the definition''s own $title?
----- Original Message -----> Hi, > > Maybe I''m going nuts, but I could have sworn reading about a trick or > new feature which allowed to have a definition parameter get a > default value of the definition''s own $title (instead of having the hack > around the limitation with selectors and intermediate variables later on).try $name, that should do it, came in somewhere mid 2.6.x series -- 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.
Matthias Saou
2011-Jul-15 11:20 UTC
Re: [Puppet Users] Definition parameter defaulting to the definition''s own $title?
R.I.Pienaar wrote :> > Maybe I''m going nuts, but I could have sworn reading about a trick or > > new feature which allowed to have a definition parameter get a > > default value of the definition''s own $title (instead of having the hack > > around the limitation with selectors and intermediate variables later on). > > try $name, that should do it, came in somewhere mid 2.6.x seriesYup, that was it! Section "$name can now be used to set default values in defined resource types" in the release notes : https://projects.puppetlabs.com/projects/puppet/wiki/Release_Notes And this is the original feature request : https://projects.puppetlabs.com/issues/5061 Thanks for the quick pointer :-) Matthias -- Clean custom Red Hat Linux rpm packages : http://freshrpms.net/ Fedora release 14 (Laughlin) - Linux kernel 2.6.35.13-91.fc14.x86_64 Load : 0.33 0.39 0.55 -- 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.
Matthias Saou
2011-Jul-20 08:43 UTC
Re: [Puppet Users] Definition parameter defaulting to the definition''s own $title?
Matthias Saou wrote :> > try $name, that should do it, came in somewhere mid 2.6.x series > > Yup, that was it! > > Section "$name can now be used to set default values in defined > resource types" in the release notes : > https://projects.puppetlabs.com/projects/puppet/wiki/Release_NotesMaybe I''m asking for too much, but is the same thing achievable when calling a definition? I''ve tried with $name but it takes the value of the parent element. Basically what I''d like to do is : node ''myvmhost'' { createvm { [ ''vm01'', ''vm02'', ''vm03'', ''vm04'', ''vm05'' ]: # VNC Port 59XY for vmXY vncport => regsubst($name, ''vm'', ''59''), } } For two reasons : * This prevents from iterating many identical calls to the definition * The definition is in a generic module for which it does not make sense to default the parameter to this calculated value. With $name I get the ''myvmhost'' string using puppet 2.6.9, but I''d like to have access to the ''vmXY'' string instead. Is that possible? Matthias -- Clean custom Red Hat Linux rpm packages : http://freshrpms.net/ Fedora release 14 (Laughlin) - Linux kernel 2.6.35.13-91.fc14.x86_64 Load : 0.21 0.22 0.27 -- 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.
vagn scott
2011-Jul-20 13:16 UTC
Re: [Puppet Users] Definition parameter defaulting to the definition''s own $title?
On 07/20/2011 04:43 AM, Matthias Saou wrote:> * The definition is in a generic module for which it does not make > sense to default the parameter to this calculated value. >Instead of passing in the port number you could pass a template for its creation node ''myvmhost'' { createvm { [ ''vm01'', ''vm02'', ''vm03'', ''vm04'', ''vm05'' ]: # VNC Port 59XY for vmXY vncport_template => "<%= name.sub(''vm'', ''59'') -%>", } } and in createvm do $vncport = inline_template($vncport_template) -- vagn -- 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.
vagn scott
2011-Jul-20 13:19 UTC
Re: [Puppet Users] Definition parameter defaulting to the definition''s own $title?
On 07/20/2011 04:43 AM, Matthias Saou wrote:> node ''myvmhost'' { > createvm { [ ''vm01'', ''vm02'', ''vm03'', ''vm04'', ''vm05'' ]: > # VNC Port 59XY for vmXY > vncport => regsubst($name, ''vm'', ''59''), > } > } >that looks like an interesting module. are you planning to publish it? Or, could I get a copy to study, whether fully working or not? Thanks, -- vagn -- 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.