def replace_line(hiera_key)
hiera_item = @config_items.fetch( hiera_key )
full_yaml_string = hiera_item.to_yaml_s
if full_yaml_string.nil?
raise InternalError.new("YAML string for #{hiera_key} is not set")
end
full_yaml_lines = full_yaml_string.split("\n")
yaml_line = full_yaml_lines.select { |line| line =~ /^#{hiera_key}\s*:/ }
if yaml_line.empty?
raise InternalError.new("YAML string for #{hiera_key} missing <key: value> line")
end
yaml_line = yaml_line[0]
debug( "Replacing #{hiera_key} in #{File.basename(@file)}" )
yaml = IO.readlines(@file)
File.open(@file, "w") do |f|
yaml.each do |line|
line.chomp!
if line =~ /^#{hiera_key}\s*:/
f.puts yaml_line
else
f.puts line
end
end
end
end