Sha256: 44a05db7819f5bb2a07fa9f25d7e47842d461d49df086b30be3f6912b3cbd38f

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 Bytes

Contents

# frozen_string_literal: true

require 'bolt/error'

# Sets a particular feature to present on a target.

Puppet::Functions.create_function(:set_feature) do
  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

    inventory.set_feature(target, feature, value)

    target
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bolt-0.20.6 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb
bolt-0.20.5 bolt-modules/boltlib/lib/puppet/functions/set_feature.rb