Sha256: 8852a5c15393388b675850b7b65da258d90f624d9719a1fd3a561750083988ce

Contents?: true

Size: 1.3 KB

Versions: 33

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

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

module Bolt
  module Transport
    class Remote < Base
      # 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 = {}, position = [])
        proxy_target = get_proxy(target)
        transport = @executor.transport(proxy_target.transport)
        arguments = arguments.merge('_target' => target.to_h.compact)

        remote_task = task.remote_instance

        result = transport.run_task(proxy_target, remote_task, arguments, options, position)
        Bolt::Result.new(target, value: result.value, action: 'task', object: task.name)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
bolt-3.3.0 lib/bolt/transport/remote.rb
bolt-3.1.0 lib/bolt/transport/remote.rb
bolt-3.0.1 lib/bolt/transport/remote.rb
bolt-3.0.0 lib/bolt/transport/remote.rb
bolt-2.44.0 lib/bolt/transport/remote.rb
bolt-2.42.0 lib/bolt/transport/remote.rb
bolt-2.40.2 lib/bolt/transport/remote.rb
bolt-2.40.1 lib/bolt/transport/remote.rb
bolt-2.38.0 lib/bolt/transport/remote.rb
bolt-2.37.0 lib/bolt/transport/remote.rb
bolt-2.36.0 lib/bolt/transport/remote.rb
bolt-2.35.0 lib/bolt/transport/remote.rb
bolt-2.34.0 lib/bolt/transport/remote.rb