Skip to content

Commit

Permalink
Also support ansible_private_key_file for SSH connections
Browse files Browse the repository at this point in the history
  • Loading branch information
decentral1se committed May 28, 2019
1 parent b3e5d08 commit 1c1b9f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ def get_vars(host):
'host.port': '2222',
'ssh_identity_file': 'key',
}),
('host', {}, b'host ansible_host=127.0.1.1 ansible_user=u ansible_private_key_file=key ansible_port=2222 ansible_become=yes ansible_become_user=u', { # noqa
'NAME': 'paramiko',
'sudo': True,
'sudo_user': 'u',
'host.name': '127.0.1.1',
'host.port': '2222',
'ssh_identity_file': 'key',
}),
('host', {}, b'host ansible_connection=docker', {
'NAME': 'docker',
'name': 'host',
Expand Down
6 changes: 6 additions & 0 deletions testinfra/utils/ansible_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ def get_ansible_host(config, inventory, host, ssh_config=None,
kwargs['ssh_config'] = ssh_config
if ssh_identity_file is not None:
kwargs['ssh_identity_file'] = ssh_identity_file

# Support both keys as advertised by Ansible
if 'ansible_ssh_private_key_file' in hostvars:
kwargs['ssh_identity_file'] = hostvars[
'ansible_ssh_private_key_file']
elif 'ansible_private_key_file' in hostvars:
kwargs['ssh_identity_file'] = hostvars[
'ansible_private_key_file']

spec = '{}://'.format(connection)
if user:
spec += '{}@'.format(user)
Expand Down

0 comments on commit 1c1b9f9

Please sign in to comment.