Hi is there a way to replicate, in a custom define, the behavior of the "path" parameter in a File resource (for instance)? I mean, with File if you set path to a value, the path has value, but if you don''t set a value, then it uses the "name" value. I''d like to do the same with my own defines, is it possible? I''m using Debian Squeeze Puppet (2.6.2) on both agent and server. TIA -- Davide Ferrari Senior System Administrator Atrapalo S.L. -- 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.
On Thu, 2011-11-10 at 11:09 +0100, Davide Ferrari wrote:> I mean, with File if you set path to a value, the path has value, but if > you don''t set a value, then it uses the "name" value. I''d like to do the > same with my own defines, is it possible?I''ll detail a bit more: right now I do something like this to accomplish what I need define nginx::generic_vhost ( $server_name = undef, $template_name = "", $ensure = "present", $ssl = "disabled", $ssl_certs = false, $ssl_port = "443" ) { $tpl_name = $template_name ? { '''' => $name, default => $template_name } # then I always use $tpl_name .... } and it works, but I''d like to avoid using an internal variable so I try to do this with another parameter if !$server_name { $server_name = $name } but it always throws Puppet (err): Could not retrieve catalog from remote server: Error 400 on SERVER: Cannot reassign variable server_name at /etc/puppet/modules/nginx/manifests/generic_vhost.pp:21 on node static1.atr.usa Is this possible with Puppet 2.6.2? -- Davide Ferrari Senior System Administrator Atrapalo S.L. -- 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.
On Thu, Nov 10, 2011 at 11:12 AM, Davide Ferrari <davide.ferrari@atrapalo.com> wrote:> On Thu, 2011-11-10 at 11:09 +0100, Davide Ferrari wrote: > >> I mean, with File if you set path to a value, the path has value, but if >> you don''t set a value, then it uses the "name" value. I''d like to do the >> same with my own defines, is it possible? > > I''ll detail a bit more: right now I do something like this to accomplish > what I need > > define nginx::generic_vhost ( > $server_name = undef, > $template_name = "", > $ensure = "present", > $ssl = "disabled", > $ssl_certs = false, > $ssl_port = "443" > ) {What you really want to do here is define nginx::generic_vhost ( $server_name = $name, ... $name becomes in scope in the parameters with feature #5061 in 2.6.5: http://projects.puppetlabs.com/projects/1/wiki/Release_Notes#2.6.5> $tpl_name = $template_name ? { > '''' => $name, > default => $template_name > } > > # then I always use $tpl_name > .... > > } > > and it works, but I''d like to avoid using an internal variable so I try > to do this with another parameter > > > if !$server_name { > $server_name = $name > } > > but it always throws > > Puppet (err): Could not retrieve catalog from remote server: Error 400 > on SERVER: Cannot reassign variable server_name > at /etc/puppet/modules/nginx/manifests/generic_vhost.pp:21 on node > static1.atr.usa > > Is this possible with Puppet 2.6.2?No, you already declared $server_name in the parameter list and you can''t reassign the value again. Since you are not on 2.6.5+, in earlier versions this is accomplished via another variable and providing a default when it''s '''': $real_sname = ? $server_name { '''' => $name, default => $server_name, } 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.
On Nov 10, 5:12 am, Davide Ferrari <davide.ferr...@atrapalo.com> wrote:> On Thu, 2011-11-10 at 11:09 +0100, Davide Ferrari wrote: > > I mean, with File if you set path to a value, the path has value, but if > > you don''t set a value, then it uses the "name" value. I''d like to do the > > same with my own defines, is it possible? > > I''ll detail a bit more: right now I do something like this to accomplish > what I need > > define nginx::generic_vhost ( > $server_name = undef, > $template_name = "", > $ensure = "present", > $ssl = "disabled", > $ssl_certs = false, > $ssl_port = "443" > ) { > > $tpl_name = $template_name ? { > '''' => $name, > default => $template_name > } > > # then I always use $tpl_name > .... > > } > > and it works, but I''d like to avoid using an internal variable so I try > to do this with another parameter > > if !$server_name { > $server_name = $name > } > > but it always throws > > Puppet (err): Could not retrieve catalog from remote server: Error 400 > on SERVER: Cannot reassign variable server_name > at /etc/puppet/modules/nginx/manifests/generic_vhost.pp:21 on node > static1.atr.usaYou have already found the usual pattern for achieving what you ask. Puppet variables -- including class and definition parameters -- can be assigned values only once, and that''s unlikely to change in the foreseeable future. John -- 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.