Sha256: d950dc00ad4ad10f4c522a7dd8e9aa62cb431a440414246d1d02196023b35622

Contents?: true

Size: 1.37 KB

Versions: 26

Compression:

Stored size: 1.37 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
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 [Undef]
  # @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(
        Puppet::Pops::Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, operation: '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

26 entries across 26 versions & 1 rubygems

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