Module: Beaker::Options::HostsFileParser
- Defined in:
- lib/beaker/options/hosts_file_parser.rb
Overview
A set of functions to parse hosts files
Class Method Summary collapse
-
.parse_hosts_file(hosts_file_path = nil) ⇒ OptionsHash
Read the contents of the hosts.cfg into an OptionsHash, merge the ‘CONFIG’ section into the OptionsHash, return OptionsHash.
Class Method Details
.parse_hosts_file(hosts_file_path = nil) ⇒ OptionsHash
Read the contents of the hosts.cfg into an OptionsHash, merge the ‘CONFIG’ section into the OptionsHash, return OptionsHash
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/beaker/options/hosts_file_parser.rb', line 15 def self.parse_hosts_file(hosts_file_path = nil) = Beaker::Options::OptionsHash.new ['HOSTS'] ||= {} unless hosts_file_path return end hosts_file_path = File.(hosts_file_path) unless File.exists?(hosts_file_path) raise ArgumentError, "Host file '#{hosts_file_path}' does not exist!" end begin = .merge(YAML.load_file(hosts_file_path)) rescue Psych::SyntaxError => e raise ArgumentError, "#{hosts_file_path} is not a valid YAML file\n\t#{e}" end # Make sure the roles array is present for all hosts ['HOSTS'].each_key do |host| ['HOSTS'][host]['roles'] ||= [] end if .has_key?('CONFIG') = .merge(.delete('CONFIG')) end end |