[Puppet Users] Optional values from Hiera (no default value)

2012-04-26 Thread Lars Francke
Hello Puppet List,

I'm writing a module that should take an optional value and I want to
get it (amongst other places) from Hiera.

$repository = $::java_repository ? {
  undef   = hiera('java_repository')
  default = $::java_repository,
}

But this fails because Hiera raises an error if it can't find a value.

I later want to do something like this:

if $repository {
  Class[$repository] - Class['java::install']
}

I tried following the examples from the recent blog series about
module design but I'm still very much learning so this might not even
be the best way to go about this. Any hints would be appreciated.

Cheers,
Lars

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



Re: [Puppet Users] Optional values from Hiera (no default value)

2012-04-26 Thread Tim Mooney

In regard to: [Puppet Users] Optional values from Hiera (no default value),...:


Hello Puppet List,

I'm writing a module that should take an optional value and I want to
get it (amongst other places) from Hiera.

$repository = $::java_repository ? {
 undef   = hiera('java_repository')
 default = $::java_repository,
}


hiera() can take a second argument which is the default you want to
supply if no data store provides a value.  Before you ask, no, I don't
know where that's documented, but we've been using it for a while in
our puppet manifests and it has been mentioned on the list even today.

Tim
--
Tim Mooney tim.moo...@ndsu.edu
Enterprise Computing  Infrastructure  701-231-1076 (Voice)
Room 242-J6, IACC Building 701-231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164

--
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



Re: [Puppet Users] Optional values from Hiera (no default value)

2012-04-26 Thread Lars Francke
Hey Tim,

thanks for your answer.

 hiera() can take a second argument which is the default you want to
 supply if no data store provides a value.  Before you ask, no, I don't
 know where that's documented, but we've been using it for a while in
 our puppet manifests and it has been mentioned on the list even today.

I actually knew about that already but if I use that I'll have to
revert to some magic value as the default because it can't be nil
for example

I'd have to do hiera('foo', 'MAGIC') and then check for 'MAGIC' in my
if statement. That's not a big deal but I had hoped there would be a
way to have a really optional lookup.

Cheers,
Lars

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.