Skip to content

Instantly share code, notes, and snippets.

@dholth
Forked from anonymous/group_names.rb
Created May 19, 2011 20:36
Show Gist options
  • Save dholth/981682 to your computer and use it in GitHub Desktop.
Save dholth/981682 to your computer and use it in GitHub Desktop.
centauri :: ~/test » cat x.txt
lkdjafs
lsjdkflkasjdf;lkajsdf
ajdsf
akjsdf
dsjflkasdfj
Installed Groups
a
b
c
Available Groups
d
e
f
require 'facter'
Facter.add("group_names") do
setcode do
file = "x.txt"
start = false
finish = false
data = []
return nil unless File.exists?(file)
File.read(file).each_line do |l|
finish = true if l =~ /^Available Groups/
data << l.chomp if start and not finish
start = true if l =~ /^Installed Groups/
end
require 'pp'
data.reject { |item| item.empty? }.join(",")
end
end
centauri :: ~/test » facter group_names
a,b,c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment