Frederiko Costa
2013-Sep-21 03:30 UTC
[Puppet Users] symlink creation using facter, but facter is nil at first run.
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+unsubscribe@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.
jcbollinger
2013-Sep-23 14:13 UTC
[Puppet Users] Re: symlink creation using facter, but facter is nil at first run.
On Friday, September 20, 2013 10:30:46 PM UTC-5, Frederiko Costa 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. > >Facts are THE way to communicate information about the current state of your nodes to the master to inform catalog compilation. If you have a chicken & egg problem then it is not facter''s fault, it is yours: your custom fact is not suitable for the use to which you are trying to put it. Evidently, it determines the JDK version by a mechanism that depends on the symlink you described, and clearly such a fact cannot be used to direct the form of the symlink. You have at least two options: 1. Come up with a better way to determine which JDK is installed. For example, if you are installing the JDK via your system''s packaging system (yum / apt / etc.) then your custom fact could querythe package manager to extract the information you want. 2. Instead of inquiring which JDK version is installed, you could choose what version you want to be installed, and have Puppet make it so. John -- 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+unsubscribe@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.
Chris McDermott
2013-Sep-25 04:44 UTC
Re: [Puppet Users] symlink creation using facter, but facter is nil at first run.
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 <frederiko@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+unsubscribe@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+unsubscribe@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.
Frederiko Costa
2013-Sep-25 15:09 UTC
Re: [Puppet Users] symlink creation using facter, but facter is nil at first run.
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 <csmcdermott@gmail.com>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 <frederiko@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+unsubscribe@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+unsubscribe@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+unsubscribe@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.