Sha256: d6fff1dec9e59388b7a79dc1f9500128d806dd1f89800f754a6d290102289e02

Contents?: true

Size: 1.53 KB

Versions: 17

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Set configuration options on a target
#
# **NOTE:** Not available in apply block
# **NOTE:** Only compatible with inventory v2
Puppet::Functions.create_function(:set_config) do
  # @param target The Target object to configure. See {get_targets}.
  # @param key_or_key_path The configuration setting to update.
  # @param value The configuration value
  # @return The Target with the updated config
  # @example Set the transport for a target
  #   set_config($target, 'transport', 'ssh')
  # @example Set the ssh password
  #   set_config($target, ['ssh', 'password'], 'secret')
  # @example Overwrite ssh config
  #   set_config($target, 'ssh', { user => 'me', password => 'secret' })
  dispatch :set_config do
    param 'Target', :target
    param 'Variant[String, Array[String]]', :key_or_key_path
    param 'Any', :value
    return_type 'Target'
  end

  def set_config(target, key_or_key_path, value = true)
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue
        .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'set_config')
    end

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

    unless inventory.version > 1
      raise Puppet::ParseErrorWithIssue
        .from_issue_and_stack(Bolt::PAL::Issues::UNSUPPORTED_INVENTORY_VERSION, action: 'set_config')
    end

    inventory.set_config(target, key_or_key_path, value)

    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_config.rb
bolt-1.48.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.47.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.45.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.44.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.43.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.42.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.41.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.40.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.39.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.38.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.37.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.36.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.35.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.34.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.33.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb
bolt-1.32.0 bolt-modules/boltlib/lib/puppet/functions/set_config.rb