Sha256: bcb3973ab100cd2992385358f6fe49ab0ef87b286bc229b787e314edfac06a47

Contents?: true

Size: 1.08 KB

Versions: 70

Compression:

Stored size: 1.08 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)
    # Send Analytics Report
    executor.report_function_call(self.class.name)

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

    target
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
bolt-3.29.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.28.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.27.4 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.27.2 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.27.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.26.2 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.26.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.25.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.24.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.23.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.23.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.22.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.22.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.21.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.20.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.19.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.18.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.17.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.16.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-3.16.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb