Sha256: 64d955b228e2cd7abb3e43be83cbfa3748938570721ae5cee5ec21834135d842

Contents?: true

Size: 1.32 KB

Versions: 30

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Parses common ways of referring to targets and returns an array of Targets.
Puppet::Functions.create_function(:get_targets) do
  # @param names A pattern or array of patterns identifying a set of targets.
  # @return A list of unique Targets resolved from any target URIs and groups.
  # @example Resolve a group
  #   get_targets('group1')
  # @example Resolve a target URI
  #   get_targets('winrm://host2:54321')
  # @example Resolve array of groups and/or target URIs
  #   get_targets(['host1', 'group1', 'winrm://host2:54321'])
  # @example Resolve string consisting of a comma-separated list of groups and/or target URIs
  #   get_targets('host1,group1,winrm://host2:54321')
  # @example Run on localhost
  #   get_targets('localhost')
  dispatch :get_targets do
    param 'Boltlib::TargetSpec', :names
    return_type 'Array[Target]'
  end

  def get_targets(names)
    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

    executor = Puppet.lookup(:bolt_executor) { nil }
    executor&.report_function_call('get_targets')

    inventory.get_targets(names)
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
bolt-1.19.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.18.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.17.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.16.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.15.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.14.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.13.1 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.13.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.12.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.11.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.10.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.9.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.8.1 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.8.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.7.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.6.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.5.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.4.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.3.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb
bolt-1.2.0 bolt-modules/boltlib/lib/puppet/functions/get_targets.rb