Created
October 2, 2014 02:51
-
-
Save muraoka-edo/b1eddce949be9a24cb6b to your computer and use it in GitHub Desktop.
[Ruby] Serverspec's property genarator(YAML Format)
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 | |
# coding: utf-8 | |
require 'yaml' | |
require 'csv' | |
class GeneratorYmlProps | |
def initialize(hostlst) | |
@hostlst = hostlst | |
@property = Hash.new { |hash,key| hash[key] ={} } | |
_generate_properties | |
end | |
def _generate_properties | |
CSV.foreach(@hostlst, { :col_sep => ',', | |
:headers => true, | |
:skip_blanks => true, | |
}) do |row| | |
host = row["host" ] | |
attrs = row["attrs"].split(':') | |
@property[host][:roles] = attrs | |
@property[host][:host_name] = host | |
end | |
puts _dump_yml | |
end | |
def _dump_yml | |
YAML.dump(@property) | |
end | |
end | |
__END__ | |
# SAMPLE | |
#host,attrs | |
#hogesrv,os:apache | |
#foosrv,os |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment