Sha256: 1eab368df1754e5a871a38f39a976257f5c62ac6dbfbfee19f98854b3e23eae9

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Sets a particular feature to present on a target.
#
# Features are used to determine what implementation of a task should be run.
# Currently supported features are
# - powershell
# - shell
# - puppet-agent
#
# **NOTE:** Not available in apply block
Puppet::Functions.create_function(:set_feature) do
  # @param target The Target object to add features to. See {get_targets}.
  # @param feature The string identifying the feature.
  # @param value Whether the feature is supported.
  # @return The target with the updated feature
  # @example Add the puppet-agent feature to a target
  #   set_feature($target, 'puppet-agent', true)
  dispatch :set_feature do
    param 'Target', :target
    param 'String', :feature
    optional_param 'Boolean', :value
  end

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

    inventory = Puppet.lookup(:bolt_inventory) { nil }

    unless inventory
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_MISSING_BOLT, action: _('set feature')
      )
    end

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

    inventory.set_feature(target, feature, value)

    target
  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_feature.rb
bolt-1.18.0 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb
bolt-1.17.0 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb
bolt-1.16.0 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb
bolt-1.15.0 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb
bolt-1.14.0 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb
bolt-1.13.1 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb
bolt-1.13.0 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb