Puppet Function: complyadm::save_yaml_key_value

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

Overview

complyadm::save_yaml_key_value(String $key, String $value, String $relative_file_path)Boolean

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

Parameters:

  • data

    A hash to write as yaml

  • relative_file_path (String)

    path relative to the bolt project

  • key (String)
  • value (String)

Returns:

  • (Boolean)

    true



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

Puppet::Functions.create_function(:'complyadm::save_yaml_key_value') do
  # @param data A hash to write as yaml
  # @param relative_file_path path relative to the bolt project
  # @return true
  dispatch :save_yaml_key_value do
    param 'String', :key
    param 'String', :value
    param 'String', :relative_file_path
    return_type 'Boolean'
  end

  def save_yaml_key_value(key, value, relative_file_path)
    boltdir = call_function('complyadm::bolt_project_dir')
    abs_file_path = File.expand_path(relative_file_path, boltdir)
    data = YAML.load_file abs_file_path
    data['complyadm::config'][key] = value
    File.open(abs_file_path, 'w') do |file|
      file.write data.to_yaml
    end
    true
  end
end