Skip to content

Commit

Permalink
fix: detect keypair generation errors when using 'opensshbin' backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajpantuso committed Aug 11, 2023
1 parent 5526fca commit 9bfd0cd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions plugins/module_utils/openssh/backends/keypair_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
)


class BackendError(Exception):
pass


@six.add_metaclass(abc.ABCMeta)
class KeypairBackend(OpensshModule):

Expand Down Expand Up @@ -208,7 +212,7 @@ def _generate_temp_keypair(self):

try:
self._generate_keypair(temp_private_key)
except (IOError, OSError) as e:
except (IOError, OSError, BackendError) as e:
self.module.fail_json(msg=to_native(e))

for f in (temp_private_key, temp_public_key):
Expand Down Expand Up @@ -323,7 +327,11 @@ def __init__(self, module):
self.ssh_keygen = KeygenCommand(self.module)

def _generate_keypair(self, private_key_path):
self.ssh_keygen.generate_keypair(private_key_path, self.size, self.type, self.comment)
rc, stdout, stderr = self.ssh_keygen.generate_keypair(private_key_path, self.size, self.type, self.comment)
if rc < 1:
return

raise BackendError(stderr)

def _get_private_key(self):
private_key_content = self.ssh_keygen.get_private_key(self.private_key_path)[1]
Expand Down

0 comments on commit 9bfd0cd

Please sign in to comment.