Sha256: 63680602c633e09b3e4d2f31b21dc0124dc8563c66a20eb8ba759cd0a9fc36b4

Contents?: true

Size: 1.06 KB

Versions: 19

Compression:

Stored size: 1.06 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

19 entries across 19 versions & 1 rubygems

Version Path
bolt-2.15.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.14.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.13.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.12.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.11.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.11.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.10.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.9.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.8.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.7.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.6.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.5.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.4.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.3.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.3.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.2.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.1.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.0.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-2.0.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb