Skip to content

Instantly share code, notes, and snippets.

@raphink
Last active July 10, 2019 09:42
Show Gist options
  • Save raphink/34721469cfab7a683d5174e851459d03 to your computer and use it in GitHub Desktop.
Save raphink/34721469cfab7a683d5174e851459d03 to your computer and use it in GitHub Desktop.
require 'augeas'
Facter.add(:web_stack) do
aug = Augeas.open()
setcode do
ps = Facter::Util::Resolution.exec('ps axuww')
listen = []
servernames = []
if ps =~ /apache2/
engine = 'apache'
aug.match('/files/etc/apache2//directive[.=~regexp("listen", "i")]').each do |l|
listen << aug.get("#{l}/arg")
end
aug.match('/files/etc/apache2//VirtualHost//directive[.=~regexp("servername", "i")]').each do |m|
servernames << aug.get("#{m}/arg")
end
elsif ps =~ /httpd/
engine = 'apache'
aug.match('/files/etc/httpd//directive[.=~regexp("listen", "i")]').each do |l|
listen << aug.get("#{l}/arg")
end
aug.match('/files/etc/httpd//VirtualHost//directive[.=~regexp("servername", "i")]').each do |m|
servernames << aug.get("#{m}/arg")
end
elsif ps =~ /nginx/
engine = 'nginx'
aug.match('/files/etc/nginx//listen').each do |l|
listen << aug.get(l).split.first.split(':')[1]
end
aug.match('/files/etc/nginx//server_name').each do |m|
servernames << aug.get(m).split
end
end
{
'engine' => engine,
'listen' => listen.uniq,
'servernames' => servernames.flatten.uniq,
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment