From 96f000c5ea1fa3e2330106dbd21fcbf3d6a64a2b Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 30 Oct 2018 14:58:35 +0000 Subject: [PATCH] ansible: tilde-expand SSH key before passing to SSH; closes #334. --- ansible_mitogen/connection.py | 8 +++++++- tests/ansible/integration/ssh/all.yml | 1 + tests/ansible/integration/ssh/config.yml | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/ansible/integration/ssh/config.yml diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index f2725e9d..df10884a 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -92,6 +92,12 @@ def _connect_ssh(spec): else: check_host_keys = 'ignore' + # #334: tilde-expand private_key_file to avoid implementation difference + # between Python and OpenSSH. + private_key_file = spec['private_key_file'] + if private_key_file is not None: + private_key_file = os.path.expanduser(private_key_file) + return { 'method': 'ssh', 'kwargs': { @@ -101,7 +107,7 @@ def _connect_ssh(spec): 'password': optional_secret(spec['password']), 'port': spec['port'], 'python_path': spec['python_path'], - 'identity_file': spec['private_key_file'], + 'identity_file': private_key_file, 'identities_only': False, 'ssh_path': spec['ssh_executable'], 'connect_timeout': spec['ansible_ssh_timeout'], diff --git a/tests/ansible/integration/ssh/all.yml b/tests/ansible/integration/ssh/all.yml index 2425943a..a8335ab7 100644 --- a/tests/ansible/integration/ssh/all.yml +++ b/tests/ansible/integration/ssh/all.yml @@ -1,2 +1,3 @@ +- import_playbook: config.yml - import_playbook: timeouts.yml - import_playbook: variables.yml diff --git a/tests/ansible/integration/ssh/config.yml b/tests/ansible/integration/ssh/config.yml new file mode 100644 index 00000000..07ad1c21 --- /dev/null +++ b/tests/ansible/integration/ssh/config.yml @@ -0,0 +1,19 @@ +# issue #334: test expanduser() on key file during config generation. + +- name: integration/ssh/config.yml + hosts: test-targets + connection: ssh + vars: + ansible_private_key_file: ~/fakekey + tasks: + - meta: end_play + when: not is_mitogen + + - mitogen_get_stack: + register: out + + - assert: + that: | + out.result[0].kwargs.identity_file == ( + lookup('env', 'HOME') + '/fakekey' + )