Sha256: 98741728c7ef3ff5489f5acf317ac8c4c27b35c5111bbdc021fe62524f378514

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 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 [Undef]
  # @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
  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) { nil }

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

    executor = Puppet.lookup(:bolt_executor) { nil }
    executor&.report_function_call('set_var')

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bolt-1.19.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.18.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.17.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.16.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.15.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.14.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.13.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.13.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb