Re: [Puppet Users] $title as default value for argument in defintion

2010-03-08 Thread Thomas Bellman

robert.gstoehl wrote:


I'd like to provide a definition with an argument which is optional
and defaults to the title:

net::route_default{"first": gateway => "192.168.0.1"}
or the shortcut:
net::route_default{"192.168.0.1"}


Do it like this:

define route_default($gateway="")
{
if $gateway == "" {
$xgateway = $title
} else {
$xgateway = $gateway
}
# Use $xgateway here instead of $gateway
}



  define route_default($gateway=$title) {
exec {"echo $gateway >> /etc/defaultrouter":
  unless  => "grep $gateway /etc/defaultrouter"
}
...
Funny - puppet substitutes $title with the fully qualified hostname -
can someone shed some light on this one? :)


The default values for definition parameters are evaluated when the
definition is defined, not when the definition is used.  And when
you are outside of definitions, $title is set to the node name.


/Bellman

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



[Puppet Users] $title as default value for argument in defintion

2010-03-08 Thread robert.gstoehl
Hey there,

I'd like to provide a definition with an argument which is optional
and defaults to the title:

net::route_default{"first": gateway => "192.168.0.1"}
or the shortcut:
net::route_default{"192.168.0.1"}


class net {
  define route_default($gateway=$title) {
exec {"echo $gateway >> /etc/defaultrouter":
  unless  => "grep $gateway /etc/defaultrouter"
}
...
}
node foo {
  net::route_default{"192.168.0.1"}
}

trying it with noop:

notice: //Node[myhost.local]/Net::Route_default[192.168.0.1]/Exec[echo
myhost.local >> /etc/defaultrouter]/returns: is notrun

Funny - puppet substitutes $title with the fully qualified hostname -
can someone shed some light on this one? :)

Thanks & cheers Robert

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.