Hi Chris,

Thanks for your help.

Yes, that's pretty much the approach I took. The only thing I changed was
that my facter looks at the yum repo to strip out the version and returns
the version. So, there will have a value, even if jdk is not yet installed.
Previously, I was stripping out the version by looking at the output of rpm
-qf command, which would return nil in the first time I ran the agent. By
looking at the repo via 'yum info', I can report the version when my facter
compiles for the first time and package is not yet installed.

Does that make sense?

thanks


-frederiko



On Tue, Sep 24, 2013 at 9:44 PM, Chris McDermott <[email protected]>wrote:

> 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 <[email protected]>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 [email protected].
>> To post to this group, send email to [email protected].
>> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
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