Sha256: 898aec99919d01a3c46831062c07f121881cd6bce3f3006a1ab1d758aaa0cb21

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Sets a variable { key => value } for a target.
#
# **NOTE:** Not available in apply block
Puppet::Functions.create_function(:set_var) do
  # @param target The Target object to set the variable for. See {get_targets}.
  # @param key The key for the variable.
  # @param value The value of the variable.
  # @return The target with the updated feature
  # @example Set a variable on a target
  #   $target.set_var('ephemeral', true)
  dispatch :set_var do
    param 'Target', :target
    param 'String', :key
    param 'Data', :value
    return_type 'Target'
  end

  def set_var(target, key, value)
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue
        .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'set_var')
    end

    inventory = Puppet.lookup(:bolt_inventory)
    executor = Puppet.lookup(:bolt_executor)
    executor.report_function_call(self.class.name)

    var_hash = { key => value }
    inventory.set_var(target, var_hash)

    target
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
bolt-1.49.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.48.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.47.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.45.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.44.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.43.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.42.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.41.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.40.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.39.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.38.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.37.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.36.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.35.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.34.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.33.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.32.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb