Sha256: cec03a292a884e82749c31dc83c6d5a1bb37fa346be7ac3032a6993af771a605

Contents?: true

Size: 1.33 KB

Versions: 18

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require_relative '../../bolt/task'
require_relative '../../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

18 entries across 18 versions & 1 rubygems

Version Path
bolt-4.0.0 lib/bolt/transport/remote.rb
bolt-3.29.0 lib/bolt/transport/remote.rb
bolt-3.28.0 lib/bolt/transport/remote.rb
bolt-3.27.4 lib/bolt/transport/remote.rb
bolt-3.27.2 lib/bolt/transport/remote.rb
bolt-3.27.1 lib/bolt/transport/remote.rb
bolt-3.26.2 lib/bolt/transport/remote.rb
bolt-3.26.1 lib/bolt/transport/remote.rb
bolt-3.25.0 lib/bolt/transport/remote.rb
bolt-3.24.0 lib/bolt/transport/remote.rb
bolt-3.23.1 lib/bolt/transport/remote.rb
bolt-3.23.0 lib/bolt/transport/remote.rb
bolt-3.22.1 lib/bolt/transport/remote.rb
bolt-3.22.0 lib/bolt/transport/remote.rb
bolt-3.21.0 lib/bolt/transport/remote.rb
bolt-3.20.0 lib/bolt/transport/remote.rb
bolt-3.19.0 lib/bolt/transport/remote.rb
bolt-3.18.0 lib/bolt/transport/remote.rb