Puppet Function: complyadm::save_yaml_file

Defined in:
lib/puppet/functions/complyadm/save_yaml_file.rb
Function type:
Ruby 4.x API

Overview

complyadm::save_yaml_file(Hash $data, String $relative_file_path)String[1]

Takes a hash object, calls .to_yaml and saves it to disk

Parameters:

  • data (Hash)

    A hash to write as yaml

  • relative_file_path (String)

    path relative to the bolt project

Returns:

  • (String[1])

    The absolute file path of where it was saved



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet/functions/complyadm/save_yaml_file.rb', line 5

Puppet::Functions.create_function(:'complyadm::save_yaml_file') do
  # @param data A hash to write as yaml
  # @param relative_file_path path relative to the bolt project
  # @return The absolute file path of where it was saved
  dispatch :save_yaml_file do
    param 'Hash', :data
    param 'String', :relative_file_path
    return_type 'String[1]'
  end

  def save_yaml_file(data, relative_file_path)
    boltdir = call_function('complyadm::bolt_project_dir')
    abs_file_path = File.expand_path(relative_file_path, boltdir)
    FileUtils.mkdir_p(File.dirname(abs_file_path))
    File.open(abs_file_path, 'w') do |file|
      file.write data.to_yaml
    end
    abs_file_path
  end
end