Skip to content

Commit

Permalink
use ansible_ssh_host_key_checking, fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
philfry committed Apr 22, 2024
1 parent 8e7e785 commit efd51c1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion ansible_mitogen/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ def _connect_ssh(spec):
"""
Return ContextService arguments for an SSH connection.
"""
check_host_keys = spec.mitogen_ssh_host_key_checking()
check_host_keys = spec.ansible_ssh_host_key_checking()
if check_host_keys is None:
if C.HOST_KEY_CHECKING:
check_host_keys = 'enforce'
else:
check_host_keys = 'ignore'
else:
check_host_keys = ('ignore', 'enforce')[check_host_keys]

# #334: tilde-expand private_key_file to avoid implementation difference
# between Python and OpenSSH.
Expand Down
14 changes: 11 additions & 3 deletions ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import ansible.constants as C

from ansible.module_utils.six import with_metaclass
from ansible.module_utils.parsing.convert_bool import boolean

# this was added in Ansible >= 2.8.0; fallback to the default interpreter if necessary
try:
Expand Down Expand Up @@ -386,7 +387,7 @@ def mitogen_ssh_compression(self):
"""

@abc.abstractmethod
def mitogen_ssh_host_key_checking(self):
def ansible_ssh_host_key_checking(self):
"""
Whether or not to check the ssh hostkeys
"""
Expand Down Expand Up @@ -570,8 +571,15 @@ def mitogen_ssh_debug_level(self):
def mitogen_ssh_compression(self):
return self._connection.get_task_var('mitogen_ssh_compression')

def mitogen_ssh_host_key_checking(self):
return self._connection.get_task_var('mitogen_ssh_host_key_checking')
def ansible_ssh_host_key_checking(self):
tmp = [boolean(x) for x in list(
filter(lambda x:x is not None, (
self._connection.get_task_var('ansible_ssh_host_key_checking'),
self._connection.get_task_var('ansible_host_key_checking')
)))]
if not tmp:
return None
return any(tmp)

def extra_args(self):
return self._connection.get_extra_args()
Expand Down
2 changes: 0 additions & 2 deletions docs/ansible_detailed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,6 @@ Like the :ans:conn:`ssh` except connection delegation is supported.
to 10.
* ``mitogen_ssh_keepalive_interval``: integer seconds delay between keepalive
messages. Defaults to 30.
* ``mitogen_ssh_host_key_checking``: `accept`, `enforce` or `ignore` the
remote's ssh host key


Debugging
Expand Down
3 changes: 1 addition & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Unreleased
----------

* :gh:issue:`952` Fix Ansible `--ask-become-pass`, add test coverage
* :gh:issue:`1066` Introduce `mitogen_ssh_host_key_checking` to somehow mimic
`ansible_host_key_checking`
* :gh:issue:`1066` Fix `ansible_ssh_host_key_checking`


v0.3.7 (2024-04-08)
Expand Down

0 comments on commit efd51c1

Please sign in to comment.