Sha256: 810b5fe2ab738e2cab56599e29c2137c5b53991ec3f2fa48b6bf04bab6df04a7

Contents?: true

Size: 1002 Bytes

Versions: 30

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

require 'bolt/error'

# Returns a hash of the 'vars' (variables) assigned to a target.
#
# Vars can be assigned through the inventory file or `set_var` function.
# Plan authors can call this function on a target to get the variable hash
# for that target.
Puppet::Functions.create_function(:vars) do
  # @param target The Target object to get variables from. See {get_targets}.
  # @return A hash of the 'vars' (variables) assigned to a target.
  # @example Get vars for a target
  #   $target.vars
  dispatch :vars do
    param 'Target', :target
    return_type 'Hash[String, Data]'
  end

  def vars(target)
    inventory = Puppet.lookup(:bolt_inventory) { nil }

    unless inventory
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_MISSING_BOLT, action: _('get vars')
      )
    end

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

    inventory.vars(target)
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

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