private function addKeyToSSHAgent(Workspace $workspace, ConnectionAdapterInterface $connection, $key, $eventName, EventDispatcherInterface $eventDispatcher)
    {
        $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Adding key to SSH agent...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));

        $keyFile = $workspace->getHost()->getPath().'/tmp.key';
        if ($connection->createFile($keyFile, 0700) && $connection->putContents($keyFile, $key)) {
            $result = $connection->executeCommand('ssh-add', array($keyFile));
            if ($result->isSuccessful()) {
                $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Added key to SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
            }

            $connection->delete($keyFile);

            if ($result->isSuccessful()) {
                return;
            }
        }

        $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Failed adding key to SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED, 'output.resetLine' => true)));
    }