Ask Your Question
0

Custom fact being applied to all servers how to avoid that part III

asked 2017-12-12 15:50:20 -0500

athlonxl gravatar image

updated 2017-12-13 19:37:27 -0500

Right now i have a ruby script that pulls tomcat location from version.bat. Problem with that is in some of the jobs it works fine and displays where tomcat is installed. But for others for tomcat home in puppet it shows up as Variable. That being the case I use previous suggested code from the links below to modify my original script to allow me to not only identify whether tomcat is installed on my machine or not if it is the script continues and then displays location in puppet. If there no tomcat found scripts ends so the puppet job doesn't come up with an error saying error while resolving custom fact Tomcat_home. the script i have doesn't cause any error for tomcat home if tomcat is not found but it doesn't do anything else and don't know why.

My modified script

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

  setcode do
    home = Dir.glob('C:\tempex?').sort().last()
    home = home.match(/\d/) if home.is_a?(String)
    home
  end
end

The original script that was being used:

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

# The Version command will produce an output similar to the following:
#   Using CATALINA_BASE:   "C:\tempex"
#   Using CATALINA_HOME:   "C:\tempex"
#   Using CATALINA_TMPDIR: "C:\tempex\temp"
#   Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_144\jre"
#   Using CLASSPATH:       "C:\tempex\bin\bootstrap.jar;C:\tempex\bin\tomcat-juli.jar"
#   Server version: Apache Tomcat/8.0.45
#   Server built:   Jun 26 2017 20:06:07 UTC
#   Server number:  8.0.45.0
#   OS Name:        Windows Server 2012
#   OS Version:     10.0
#   Architecture:   amd64
#   JVM Version:    1.8.0_144-b01
#   JVM Vendor:     Oracle Corporation
#
# The following code manipulates the output text to get only the Tomcat Home line (line 1), and the specific path.
# Splitting the line where the blank space is found, then taking the third text chunk ([2], since it starts on [0])
# and finally trimming off the double quotes.

  setcode do 
    home = Facter::Core::Execution.exec('c:\tempex\bin\version.bat 2>&1')
    home = home.split("\n")[1]
    home = home.split(" ")[2]
    home = home.tr('"', '')
  end
end

End result should be a script that will be able to tell tomcat is installed and then tell puppet where it is for home. When it sees there no tomcat script will end causing puppet to run with no error.

Custom fact being applied to all servers how to avoid that part I: https://ask.puppet.com/question/32776...

Custom fact being applied to all servers how to avoid that part II: https://ask.puppet.com/question/32793...

update: When i try making the changes mention below nothing change. As you can see from the image below tomcat show does not show up at tomcat is installed on server if not . The idea is to have tomcat home as C:\tempex if not the script just ends without doing anything image description

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-12-13 19:05:18 -0500

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

  setcode do
    home = Dir.glob('C:\tempex?').sort().last()
    home = home.match(/\d/) if home.is_a?(String)
    home
  end

  setcode do
    nil
  end
end

Doesn't the tomcat executable have some --version flag? Or isn't there some interesting key in the registry?

edit flag offensive delete link more

Comments

tried what you show with no results still got nothing.

athlonxl gravatar imageathlonxl ( 2017-12-13 19:38:08 -0500 )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

1 follower

Stats

Asked: 2017-12-12 15:50:20 -0500

Seen: 48 times

Last updated: Dec 13 '17