Skip to content

Instantly share code, notes, and snippets.

@ITBlogger
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ITBlogger/195ad4c1fcae2d81da64 to your computer and use it in GitHub Desktop.
Save ITBlogger/195ad4c1fcae2d81da64 to your computer and use it in GitHub Desktop.
Ruby Script to process output of command and create Ansible host list
#!/usr/bin/env ruby
whereami = "/cust/tools/bin/whereami"
ecndir = "/cust/tools/etc/envdef/envs"
sysinvfilename = "systeminventory.txt"
sysinv = File.open(sysinvfilename, "a")
dirs = Dir.entries("#{ecndir}")
dirs.sort!
dirs.each do |env|
next if env == '.' or env == '..' or env == '.svn'
wai_output = `#{whereami} --env #{env}`
sysinv.puts "[#{env}]"
wai_output.each_line do |line|
if (line['.com:'])
elements = line.split(":")
elements.delete_if{|e| e == ':'}
sysinv.puts "#{elements}"
end
end
end
sysinv.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment