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.16.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.15.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.14.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.13.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.12.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.11.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.10.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.9.2 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.9.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.9.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.8.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.8.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.7.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.7.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.6.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.6.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.5.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.4.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.3.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.1.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb