Hmm. Perhaps you could have something like this (assuming your fact is
called $jdk_version):

package { 'jdk':
  ensure => latest,
}

if ($::jdk_version) {
  file { '/usr/java/jdk':
    ensure  => link,
    target  => "/usr/java/${::jdk_version}",
    require => Package['jdk'],
  }
} else {
  exec { 'create-symlink':
    command => '/bin/ln -s /usr/java/jdk-* /usr/java/jdk',
    path    => '/bin',
    creates => '/usr/java/jdk',
    require => Package['jdk'],
  }
}

This way, in either case the jdk package would be installed first. If it
existed prior to the puppet run, the fact will evaluate to TRUE and the
file resource will ensure that the appropriate link exists. Alternatively,
if the package was not installed prior to the run, the fact will evaluate
to FALSE, but the exec will still create the appropriate symlink. But only
if the symlink doesn't already exist.

You'll still have a problem if the jdk package is updated by puppet,
however. In that case the fact would have the old version and try to ensure
that the link points to a non-existent target. Maybe there's a way to make
the exec work in that case, with a refreshonly or something, but I can't
quite think of it right now, because ln -s will fail if the link already
exists (even if it's pointing to a target that no longer exists).

Chris


On Fri, Sep 20, 2013 at 9:30 PM, Frederiko Costa <freder...@gmail.com>wrote:

> Hi all,
>
> I'm trying to find a better way to implement this, but I can't think of. I
> have a jdk module that requires to create a symlink to whatever version is
> the one installed. Say I install jdk-6u35, it will create something like
> /usr/java/jdk_1.6.35. I would like to create a symlink /usr/java/jdk whose
> target would be /usr/java/jdk_1.6.35.
>
> The point here isn't to ask how to create the symlink - that's
> straightforward. I'm in a chicken-egg problem. I'm sure there's got a
> better and easier way to do this that I can't think of.
>
> I wrote a facter to report the jdk version running. Based on the string
> returned by the facter, it works great. However, I jdk is not installed,
> this facter returns nil - the catalog is compiled and the value was nil at
> compilation time - and the file resource, property target, fails. I bypass
> this with an if clause and everything runs fine because jdk is already
> there and the symlink will be created. I know I could tell my facter to
> return something else (actually I create a link to latest, and that works,
> but it's a poor's man solution).
>
> Have any you run into this situation? Any suggestion? Not convinced if
> facter is the way to go in this particular case.
>
> Thanks,
> -fred
>
> --
> 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+unsubscr...@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.
>

-- 
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+unsubscr...@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.

Reply via email to