-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathget_target.rb
More file actions
34 lines (29 loc) · 1.08 KB
/
get_target.rb
File metadata and controls
34 lines (29 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
# frozen_string_literal: true
require 'bolt/error'
# Get a single target from inventory if it exists, otherwise create a new Target.
#
# > **Note:** Calling `get_target('all')` returns an empty array.
Puppet::Functions.create_function(:get_target) do
# @param name A Target name.
# @return A single target, either new or from inventory.
# @example Create a new Target from a URI
# get_target('winrm://host2:54321')
# @example Get an existing Target from inventory
# get_target('existing-target')
dispatch :get_target do
param 'Boltlib::TargetSpec', :name
return_type 'Target'
end
def get_target(name)
inventory = Puppet.lookup(:bolt_inventory)
# Bolt executor not expected when invoked from apply block
executor = Puppet.lookup(:bolt_executor) { nil }
# Send Analytics Report
executor&.report_function_call(self.class.name)
unless inventory.version > 1
raise Puppet::ParseErrorWithIssue
.from_issue_and_stack(Bolt::PAL::Issues::UNSUPPORTED_INVENTORY_VERSION, action: 'get_target')
end
inventory.get_target(name)
end
end