fix a bug that breaks inventory updates if no credential is supplied

see: #7206
This commit is contained in:
Ryan Petrello
2017-07-20 14:30:41 -04:00
parent 1c5b0f023e
commit 2e659244f7
2 changed files with 20 additions and 2 deletions

View File

@@ -481,14 +481,14 @@ class BaseTask(Task):
if 'OPENSSH PRIVATE KEY' in data and not openssh_keys_supported:
raise RuntimeError(OPENSSH_KEY_ERROR)
for credential, data in private_data.get('credentials', {}).iteritems():
name = 'credential_%d' % credential.pk
# OpenSSH formatted keys must have a trailing newline to be
# accepted by ssh-add.
if 'OPENSSH PRIVATE KEY' in data and not data.endswith('\n'):
data += '\n'
# For credentials used with ssh-add, write to a named pipe which
# will be read then closed, instead of leaving the SSH key on disk.
if credential.kind in ('ssh', 'scm') and not ssh_too_old:
if credential and credential.kind in ('ssh', 'scm') and not ssh_too_old:
name = 'credential_%d' % credential.pk
path = os.path.join(kwargs['private_data_dir'], name)
run.open_fifo_write(path, data)
private_data_files['credentials']['ssh'] = path