mirror of
https://github.com/ansible/awx.git
synced 2026-03-26 21:35:01 -02:30
fix a bug that breaks inventory updates if no credential is supplied
see: #7206
This commit is contained in:
@@ -481,14 +481,14 @@ class BaseTask(Task):
|
|||||||
if 'OPENSSH PRIVATE KEY' in data and not openssh_keys_supported:
|
if 'OPENSSH PRIVATE KEY' in data and not openssh_keys_supported:
|
||||||
raise RuntimeError(OPENSSH_KEY_ERROR)
|
raise RuntimeError(OPENSSH_KEY_ERROR)
|
||||||
for credential, data in private_data.get('credentials', {}).iteritems():
|
for credential, data in private_data.get('credentials', {}).iteritems():
|
||||||
name = 'credential_%d' % credential.pk
|
|
||||||
# OpenSSH formatted keys must have a trailing newline to be
|
# OpenSSH formatted keys must have a trailing newline to be
|
||||||
# accepted by ssh-add.
|
# accepted by ssh-add.
|
||||||
if 'OPENSSH PRIVATE KEY' in data and not data.endswith('\n'):
|
if 'OPENSSH PRIVATE KEY' in data and not data.endswith('\n'):
|
||||||
data += '\n'
|
data += '\n'
|
||||||
# For credentials used with ssh-add, write to a named pipe which
|
# 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.
|
# 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)
|
path = os.path.join(kwargs['private_data_dir'], name)
|
||||||
run.open_fifo_write(path, data)
|
run.open_fifo_write(path, data)
|
||||||
private_data_files['credentials']['ssh'] = path
|
private_data_files['credentials']['ssh'] = path
|
||||||
|
|||||||
@@ -1165,6 +1165,24 @@ class TestInventoryUpdateCredentials(TestJobExecution):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_source_without_credential(self):
|
||||||
|
self.instance.source = 'ec2'
|
||||||
|
|
||||||
|
def run_pexpect_side_effect(*args, **kwargs):
|
||||||
|
args, cwd, env, stdout = args
|
||||||
|
|
||||||
|
assert 'AWS_ACCESS_KEY_ID' not in env
|
||||||
|
assert 'AWS_SECRET_ACCESS_KEY' not in env
|
||||||
|
assert 'EC2_INI_PATH' in env
|
||||||
|
|
||||||
|
config = ConfigParser.ConfigParser()
|
||||||
|
config.read(env['EC2_INI_PATH'])
|
||||||
|
assert 'ec2' in config.sections()
|
||||||
|
return ['successful', 0]
|
||||||
|
|
||||||
|
self.run_pexpect.side_effect = run_pexpect_side_effect
|
||||||
|
self.task.run(self.pk)
|
||||||
|
|
||||||
def test_ec2_source(self):
|
def test_ec2_source(self):
|
||||||
aws = CredentialType.defaults['aws']()
|
aws = CredentialType.defaults['aws']()
|
||||||
self.instance.source = 'ec2'
|
self.instance.source = 'ec2'
|
||||||
|
|||||||
Reference in New Issue
Block a user