Sha256: 1f699e0835cf90e3d26e82a53283fd31a47292bd126f0e1a009072bc0c5f2e27

Contents?: true

Size: 1.05 KB

Versions: 19

Compression:

Stored size: 1.05 KB

Contents

# 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 }
    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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bolt-2.15.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.14.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.13.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.12.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.11.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.11.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.10.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.9.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.8.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.7.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.6.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.5.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.4.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.3.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.3.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.2.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.1.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.0.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.0.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb