Sha256: 02af09d77a2e3d48c0e027a6ddefef39e6bc03dc7f8b10211b6263531ba1aa10

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require 'bolt/error'

# Parses common ways of referring to targets and returns an array of Targets.
#
# Accepts input consisting of
# - a group
# - a target URI
# - an array of groups and/or target URIs
# - a string that consists of a comma-separated list of groups and/or target URIs
#
# Examples of the above would be
# - 'group1'
# - 'host1,group1,winrm://host2:54321'
# - ['host1', 'group1', 'winrm://host2:54321']
#
# Returns an array of unique Targets resolved from any target URIs and groups.
Puppet::Functions.create_function(:get_targets) do
  dispatch :get_targets do
    param 'Boltlib::TargetSpec', :names
    return_type 'Array[Target]'
  end

  def get_targets(names)
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, operation: 'get_targets'
      )
    end

    inventory = Puppet.lookup(:bolt_inventory) { nil }

    unless inventory && Puppet.features.bolt?
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_MISSING_BOLT, action: _('process targets through inventory')
      )
    end

    inventory.get_targets(names)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bolt-0.17.2 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-0.17.1 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-0.17.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb