Sha256: 0e829e2d8aba5fac9c0968191cffc10904f305258999b796caadcc25989b4ce0

Contents?: true

Size: 1.63 KB

Versions: 8

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require 'bolt/task/remote'
require 'bolt/transport/base'

module Bolt
  module Transport
    class Remote < Base
      # The options for the remote transport not defined.
      def self.filter_options(unfiltered)
        unfiltered
      end

      def self.validate(options)
        # This will fail when validating global config
        # unless options['device-type']
        #  raise Bolt::ValidationError, 'Must specify device-type for devices'
        # end
      end

      # TODO: this should have access to inventory so target doesn't have to
      def initialize(executor)
        super()

        @executor = executor
      end

      def get_proxy(target)
        inventory = target.inventory
        raise "Target was created without inventory? Not get_targets?" unless inventory
        proxy = inventory.get_targets(target.options['run-on'] || 'localhost').first

        if proxy.transport == 'remote'
          msg = "#{proxy.name} is not a valid run-on target for #{target.name} since is also remote."
          raise Bolt::Error.new(msg, 'bolt/invalid-remote-target')
        end
        proxy
      end

      # Cannot batch because arugments differ
      def run_task(target, task, arguments, options = {})
        proxy_target = get_proxy(target)
        transport = @executor.transport(proxy_target.protocol)
        arguments = arguments.merge('_target' => target.to_h.reject { |_, v| v.nil? })

        remote_task = Bolt::Task::Remote.new(task.to_h)

        result = transport.run_task(proxy_target, remote_task, arguments, options)
        Bolt::Result.new(target, value: result.value)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bolt-1.12.0 lib/bolt/transport/remote.rb
bolt-1.11.0 lib/bolt/transport/remote.rb
bolt-1.10.0 lib/bolt/transport/remote.rb
bolt-1.9.0 lib/bolt/transport/remote.rb
bolt-1.8.1 lib/bolt/transport/remote.rb
bolt-1.8.0 lib/bolt/transport/remote.rb
bolt-1.7.0 lib/bolt/transport/remote.rb
bolt-1.6.0 lib/bolt/transport/remote.rb