Sha256: 5c47f55c1918eb48d9dc98696a8905a181a61d42c8549c2e2b53612696315a6f

Contents?: true

Size: 909 Bytes

Versions: 10

Compression:

Stored size: 909 Bytes

Contents

# frozen_string_literal: true

require 'bolt/error'

# Returns a hash of the 'vars' (variables) assigned to a target through the
# inventory file or `set_var` function.
#
# Accepts no parameters.
#
# Plan authors can call this function on a target to get the variable hash
# for that target.
Puppet::Functions.create_function(:vars) do
  dispatch :vars do
    param 'Target', :target
    return_type 'Hash[String, Data]'
  end

  def vars(target)
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, operation: 'vars'
      )
    end

    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

    inventory.vars(target)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bolt-0.20.6 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.20.5 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.20.3 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.20.2 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.20.0 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.19.1 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.19.0 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.18.2 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.18.1 bolt-modules/boltlib/lib/puppet/functions/vars.rb
bolt-0.18.0 bolt-modules/boltlib/lib/puppet/functions/vars.rb