Ask Your Question

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

asked 2017-12-08 01:22:52 -0600

athlonxl gravatar image

updated 2017-12-08 03:38:11 -0600

This is a continuation from Since it was decided to go in another direction a new question is being ask. The idea is to look which exe file we have in the folder. If the file is tomcat6, then we know we're running version 6, if you have tomcat8, we're running version 8. We'll only care for the major version (6, 7, 8, etc). Still being done in puppet ruby script. This way when we look at the variable in puppet it will come up instead of it just coming up as variable. Script below would need to be easily modify for future use regarding tomcat.

original script

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

  setcode do 
    if File.exist? 'C:\tempex\bin\tomcat6.exe'
      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]

tomcat will be stored here C:\tempex\bin\tomcat6.exe or 7 or 8

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-12-11 07:08:47 -0600

Isn't that enough:

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

  setcode do
    version = Dir.glob('C:\tempex\bin\tomcat?.exe').sort().last()
    version = version.match(/\d/) if version.is_a?(String)

Don't you manage your tomcat installation via Puppet, or why do you have to determine a fact for that? What does the version.bat script do?

edit flag offensive delete link more


sometimes when tomcat home is read from version.bat script for some reason tomcat home comes up as variable instead of listing out any directory of tomcat. that being the case we decided we just set the code so if we have tomcat 6 install on server version read as tomcat 6.

athlonxl gravatar imageathlonxl ( 2017-12-11 08:41:05 -0600 )edit

if its later upgraded to tomcat 8 the script is then already setup to identify for it. Thats why we want it able to read whether it has tomcat 6,7, or 8 on the server

athlonxl gravatar imageathlonxl ( 2017-12-11 08:43:10 -0600 )edit

@Kai Burghardt how would you state an else statement in script shown when i add one errors out. Adding one so if tomcat is not found it stated for me in puppet

athlonxl gravatar imageathlonxl ( 2017-12-14 15:21:42 -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

1 follower


Asked: 2017-12-08 01:22:52 -0600

Seen: 79 times

Last updated: Dec 11 '17