Ask Your Question
0

Custom fact being applied to all servers how to avoid that

asked 2017-12-06 21:02:15 -0600

athlonxl gravatar image

updated 2017-12-07 02:18:00 -0600

Custom fact Tomcat_version is being applied to all boxes whether they have Tomcat installed or not. For those boxes with no Tomcat installed the ruby script breaks and comes back with an error, which shouldn't be happening. Coming up with a way so that this doesn't happen. The facter error for Tomcat is very simple... Boxes that have no Tomcat installed are failing to produce the custom fact. That's because the custom fact design was thought for guidewire boxes. We didn't have all the boxes in mind when we designed that. For now just need to come up with an approach on how to go about fixing that.

Facter.add(:tomcat_version) do
    confine :kernel => 'windows'

  setcode do 
    version = Facter::Core::Execution.exec('c:\tempex\bin\version.bat 2>&1')
    version = version.split("\n")[5]
    version = version.split("\/")[1]
    version = version.split("\n")[0]   end
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-12-07 05:37:03 -0600

stivesso gravatar image

Hi athlonxl,

My suggestion is that you could check the presence of tomcat startup/shutdown script ( -startup.bat/shutdown.bat- or any other file created/used by Tomcat) before setting your Custom facts. See an example of what the code might looks like below. Using that approach, on the puppet code, you can then check whether that custom facts was set or not with a simple condition if $tomcat_version {}...

Facter.add(:tomcat_version) do
    confine :kernel => 'windows'

  setcode do 
    if File.exist? 'c:\tomcat7\bin\startup.bat'
      version = Facter::Core::Execution.exec('c:\tempex\bin\version.bat 2>&1')
      version = version.split("\n")[5]
      version = version.split("\/")[1]
      version = version.split("\n")[0]
    end
  end
edit flag offensive delete link more

Comments

I like that approach my only question is can it be set to check more then just one location if need be

athlonxl gravatar imageathlonxl ( 2017-12-07 10:11:21 -0600 )edit

Hi athlonxl, I guess you can use "and" to check more than one location (if ... and ...)

stivesso gravatar imagestivesso ( 2017-12-08 00:53:47 -0600 )edit

Thanks for the answers they work out great regrettably it was decided to go in another direction. But thank you for the help. A new question has been open https://ask.puppet.com/question/32793/custom-fact-being-applied-to-all-servers-how-to-avoid-that-part-ii/

athlonxl gravatar imageathlonxl ( 2017-12-08 01:14:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-12-06 21:02:15 -0600

Seen: 45 times

Last updated: Dec 07