Last active
August 29, 2015 14:07
-
-
Save ITBlogger/195ad4c1fcae2d81da64 to your computer and use it in GitHub Desktop.
Ruby Script to process output of command and create Ansible host list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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