Skip to content

Commit 81f1226

Browse files
authored
Merge pull request #87 from ByteInternet/allow_no_ssh_key
2 parents b0a323d + 1c4b0bb commit 81f1226

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Deployer/Task/Common/PrepareSshTaskGlobal.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Hypernode\Deploy\Deployer\Task\Common;
66

7+
use Deployer\Exception\RunException;
78
use Hypernode\Deploy\Deployer\Task\TaskBase;
89
use Hypernode\DeployConfiguration\Configuration;
9-
use Symfony\Component\Process\Exception\ProcessFailedException;
1010

1111
use function Deployer\get;
1212
use function Deployer\runLocally;
@@ -31,16 +31,19 @@ public function configure(Configuration $config): void
3131
task('prepare:ssh', function () {
3232
$this->configureKey();
3333

34-
if (testLocally('ssh-add -l | grep -q "no identities"')) {
34+
$agentHasNoIdentities = testLocally('ssh-add -l | grep -q "no identities"');
35+
$sshKeyFileExists = testLocally('[ -f {{ssh_key_file}} ]');
36+
37+
if ($agentHasNoIdentities && $sshKeyFileExists) {
3538
try {
3639
runLocally('ssh-add -k {{ssh_key_file}}');
37-
} catch (ProcessFailedException $e) {
40+
} catch (RunException $e) {
3841
writeln('Failed to add key to ssh agent.');
3942
writeln('Trying key {{ssh_key_file}}');
4043
try {
4144
$keyMd5 = runLocally('md5sum {{ssh_key_file}}');
4245
writeln("With MD5 $keyMd5");
43-
} catch (ProcessFailedException $e) {
46+
} catch (RunException $e) {
4447
writeln('Failed to get keyfile MD5 ' . $e);
4548
}
4649
throw $e;

0 commit comments

Comments
 (0)