Skip to content

Instantly share code, notes, and snippets.

@muraoka-edo
Created October 2, 2014 02:51
Show Gist options
  • Save muraoka-edo/b1eddce949be9a24cb6b to your computer and use it in GitHub Desktop.
Save muraoka-edo/b1eddce949be9a24cb6b to your computer and use it in GitHub Desktop.
[Ruby] Serverspec's property genarator(YAML Format)
#!/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