Sha256: b3dc3ad0a3bf0f28d3f1be5c15513d3b7d87e72d2f84c6891106c63ead5d2027

Contents?: true

Size: 1.08 KB

Versions: 71

Compression:

Stored size: 1.08 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 }
    # 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

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
bolt-3.0.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.0.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.44.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.42.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.40.2 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.40.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.38.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.37.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.36.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.35.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.34.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.33.2 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.33.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.32.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.31.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.30.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.29.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.28.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.27.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-2.26.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb