Sha256: 4cef515d589e93222e15419f946c2e225365b2778f96ed41623d6cfbb4af63bc

Contents?: true

Size: 960 Bytes

Versions: 10

Compression:

Stored size: 960 Bytes

Contents

# frozen_string_literal: true

require 'bolt/error'

# Sets a variable { key => value } for a target.
#
# This function takes 3 parameters:
# * A Target object to set the variable for
# * The key for the variable (String)
# * The value of the variable (Data)
#
# Returns undef.
Puppet::Functions.create_function(:set_var) do
  dispatch :set_var do
    param 'Target', :target
    param 'String', :key
    param 'Data', :value
  end

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

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

    unless inventory
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_MISSING_BOLT, action: _('set a var on a target')
      )
    end

    inventory.set_var(target, key, value)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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