-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathset_var.rb
More file actions
38 lines (32 loc) · 1.08 KB
/
set_var.rb
File metadata and controls
38 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true
require 'bolt/error'
# Sets a variable `{ key => value }` for a target.
#
# > **Note:** Not available in apply block
Puppet::Functions.create_function(:set_var) do
# @param target The Target object to set the variable for. See {get_targets}.
# @param key The key for the variable.
# @param value The value of the variable.
# @return The target with the updated feature
# @example Set a variable on a target
# $target.set_var('ephemeral', true)
dispatch :set_var do
param 'Target', :target
param 'String', :key
param 'Data', :value
return_type 'Target'
end
def set_var(target, key, value)
unless Puppet[:tasks]
raise Puppet::ParseErrorWithIssue
.from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'set_var')
end
inventory = Puppet.lookup(:bolt_inventory)
executor = Puppet.lookup(:bolt_executor)
# Send Analytics Report
executor.report_function_call(self.class.name)
var_hash = { key => value }
inventory.set_var(target, var_hash)
target
end
end