Sha256: 532a72f36536094559a435535c69a3d4a86ff8ff8f13636d049515d4a6c48e51

Contents?: true

Size: 1.12 KB

Versions: 28

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Sets a variable { key => value } for a target.
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(
        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

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

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
bolt-1.12.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.11.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.10.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.9.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.8.1 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.8.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.7.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.6.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.5.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.4.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.3.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.2.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.1.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-1.0.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-0.25.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-0.24.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-0.23.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-0.22.0 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-0.21.8 bolt-modules/boltlib/lib/puppet/functions/set_var.rb
bolt-0.21.7 bolt-modules/boltlib/lib/puppet/functions/set_var.rb