Cleanup on ssh-agent failure
I'm getting an error when executing ssh-agent add. I'm not sure why and the logs don't provide any useful information nor does the application cleanup the ssh-agents when it fails. Turns out I didn't have permission to read the private ssh private key on the filesystem. Provide useful logging and cleanup here. Change-Id: I1788a57f51e3516c91e12d1e0a20a4b842cedb20 Signed-off-by: Jamie Lennox <jamielennox@gmail.com>
This commit is contained in:
parent
91fad2609f
commit
377177c03c
|
@ -118,12 +118,12 @@ class SshAgent(object):
|
||||||
env.update(self.env)
|
env.update(self.env)
|
||||||
key_path = os.path.expanduser(key_path)
|
key_path = os.path.expanduser(key_path)
|
||||||
self.log.debug('Adding SSH Key {}'.format(key_path))
|
self.log.debug('Adding SSH Key {}'.format(key_path))
|
||||||
output = ''
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(['ssh-add', key_path], env=env,
|
subprocess.check_output(['ssh-add', key_path], env=env,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as e:
|
||||||
self.log.error('ssh-add failed: {}'.format(output))
|
self.log.error('ssh-add failed. stdout: %s, stderr: %s',
|
||||||
|
e.output, e.stderr)
|
||||||
raise
|
raise
|
||||||
self.log.info('Added SSH Key {}'.format(key_path))
|
self.log.info('Added SSH Key {}'.format(key_path))
|
||||||
|
|
||||||
|
@ -613,7 +613,12 @@ class ExecutorServer(object):
|
||||||
|
|
||||||
def executeJob(self, job):
|
def executeJob(self, job):
|
||||||
self.job_workers[job.unique] = AnsibleJob(self, job)
|
self.job_workers[job.unique] = AnsibleJob(self, job)
|
||||||
self.job_workers[job.unique].run()
|
|
||||||
|
try:
|
||||||
|
self.job_workers[job.unique].run()
|
||||||
|
except Exception:
|
||||||
|
del self.job_workers[job.unique]
|
||||||
|
raise
|
||||||
|
|
||||||
def finishJob(self, unique):
|
def finishJob(self, unique):
|
||||||
del(self.job_workers[unique])
|
del(self.job_workers[unique])
|
||||||
|
@ -704,7 +709,13 @@ class AnsibleJob(object):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.ssh_agent.start()
|
self.ssh_agent.start()
|
||||||
self.ssh_agent.add(self.private_key_file)
|
|
||||||
|
try:
|
||||||
|
self.ssh_agent.add(self.private_key_file)
|
||||||
|
except Exception:
|
||||||
|
self.ssh_agent.stop()
|
||||||
|
raise
|
||||||
|
|
||||||
self.running = True
|
self.running = True
|
||||||
self.thread = threading.Thread(target=self.execute)
|
self.thread = threading.Thread(target=self.execute)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
Loading…
Reference in New Issue