if Facter.value(:kernel) == 'Linux' Facter.add('ansible_python_interpreter') do setcode do ansible_python_interpreter = Facter::Core::Execution.exec('which python3') if ansible_python_interpreter.empty? ansible_python_interpreter = Facter::Core::Execution.exec('which python') end ansible_python_interpreter end end end
if Facter.value(:kernel) == 'Linux'Facter.add(:tomcat) do confine operatingsystem: ['RedHat CentOS'] setcode do process = Facter::Core::Execution.exec('ps -ef | grep [^]]java | grep catalina') tomcatinfo = Array.new({}) regex = %r{/.*catalina.base\=(.*?) .*/} home = process[regex, 1] if home tomcatinfo.push('tomcat.base' => home) info = Facter::Core::Execution.exec(home + '/bin/version.sh') info = info.split(%r{/\n/}) info.each do |x| tmp = x.split(%r{/:/}) if tmp[0] =~ %r{/.*erver.*umber/} tomcatinfo.push('tomcat.version' => tmp[1].chomp.strip) end if tmp[0] =~ %r{/JVM Version/} tomcatinfo.push('tomcat.jvm' => tmp[1].chomp.strip) end end tomcatinfo end end end
require 'json' Facter.add(:yum_repos) do confine operatingsystem: ['RedHat CentOS'] setcode do repos = Array.new({}) # list enabled yum repos enabled_repos = Facter::Core::Execution.execute("/usr/bin/yum repolist enabled | awk '!/repo id/ && !/repolist/ && !/Load/' | awk '{print $1}'") splitstring = enabled_repos.split("\n") splitstring.each { |reponame| repos.push(reponame => true) } # list disabled yum repos enabled_repos = Facter::Core::Execution.execute("/usr/bin/yum repolist disabled | awk '!/repo id/ && !/repolist/ && !/Load/' | awk '{print $1}'") splitstring = enabled_repos.split("\n") splitstring.each { |reponame| repos.push(reponame => false) } repos end end