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-4.0.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.29.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.28.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.27.4 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.27.2 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.27.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.26.2 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.26.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.25.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.24.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.23.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.23.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.22.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.22.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.21.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.20.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.19.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.18.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.17.0 bolt-modules/boltlib/lib/puppet/functions/get_target.rb
bolt-3.16.1 bolt-modules/boltlib/lib/puppet/functions/get_target.rb