-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathset_feature.rb
More file actions
43 lines (37 loc) · 1.3 KB
/
set_feature.rb
File metadata and controls
43 lines (37 loc) · 1.3 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
39
40
41
42
43
# frozen_string_literal: true
require 'bolt/error'
# Sets a particular feature to present on a target.
#
# Features are used to determine what implementation of a task should be run.
# Supported features are:
# - `powershell`
# - `shell`
# - `puppet-agent`
#
# > **Note:** Not available in apply block
Puppet::Functions.create_function(:set_feature) do
# @param target The Target object to add features to. See {get_targets}.
# @param feature The string identifying the feature.
# @param value Whether the feature is supported.
# @return The target with the updated feature
# @example Add the `puppet-agent` feature to a target
# set_feature($target, 'puppet-agent', true)
dispatch :set_feature do
param 'Target', :target
param 'String', :feature
optional_param 'Boolean', :value
return_type 'Target'
end
def set_feature(target, feature, value = true)
unless Puppet[:tasks]
raise Puppet::ParseErrorWithIssue
.from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'set_feature')
end
inventory = Puppet.lookup(:bolt_inventory)
executor = Puppet.lookup(:bolt_executor)
# Send Analytics Report
executor.report_function_call(self.class.name)
inventory.set_feature(target, feature, value)
target
end
end