Skip to content

Commit 5749845

Browse files
moreatiphilfry
andcommitted
ansible_mitogen: Fix ansible_host_key_checking combined with add_host
fixes #1066 Co-authored-by: Philippe Kueck <[email protected]>
1 parent 4b048ca commit 5749845

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

ansible_mitogen/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _connect_ssh(spec):
119119
"""
120120
Return ContextService arguments for an SSH connection.
121121
"""
122-
if C.HOST_KEY_CHECKING:
122+
if spec.host_key_checking():
123123
check_host_keys = 'enforce'
124124
else:
125125
check_host_keys = 'ignore'

ansible_mitogen/transport_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363

6464
import abc
6565
import os
66+
67+
import ansible.module_utils.parsing.convert_bool
6668
import ansible.utils.shlex
6769
import ansible.constants as C
6870

@@ -245,6 +247,12 @@ def python_path(self):
245247
Path to the Python interpreter on the target machine.
246248
"""
247249

250+
@abc.abstractmethod
251+
def host_key_checking(self):
252+
"""
253+
Whether or not to check the keys of the target machine
254+
"""
255+
248256
@abc.abstractmethod
249257
def private_key_file(self):
250258
"""
@@ -466,6 +474,14 @@ def python_path(self, rediscover_python=False):
466474
action=self._action,
467475
rediscover_python=rediscover_python)
468476

477+
def host_key_checking(self):
478+
def candidates():
479+
yield self._connection.get_task_var('ansible_ssh_host_key_checking')
480+
yield self._connection.get_task_var('ansible_host_key_checking')
481+
yield C.HOST_KEY_CHECKING
482+
val = next(v for v in candidates() if v is not None)
483+
return ansible.module_utils.parsing.convert_bool.boolean(val)
484+
469485
def private_key_file(self):
470486
return self._play_context.private_key_file
471487

@@ -692,6 +708,14 @@ def python_path(self, rediscover_python=False):
692708
action=self._action,
693709
rediscover_python=rediscover_python)
694710

711+
def host_key_checking(self):
712+
def candidates():
713+
yield self._host_vars.get('ansible_ssh_host_key_checking')
714+
yield self._host_vars.get('ansible_host_key_checking')
715+
yield C.HOST_KEY_CHECKING
716+
val = next(v for v in candidates() if v is not None)
717+
return ansible.module_utils.parsing.convert_bool.boolean(val)
718+
695719
def private_key_file(self):
696720
# TODO: must come from PlayContext too.
697721
return (

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Unreleased
2424
* :gh:issue:`952` Fix Ansible `--ask-become-pass`, add test coverage
2525
* :gh:issue:`957` Fix Ansible exception when executing against 10s of hosts
2626
"ValueError: filedescriptor out of range in select()"
27+
* :gh:issue:`1066` Allow Ansible host key checking to be overridden by
28+
`ansible_host_key_checking` & `ansible_ssh_host_key_checking`
2729

2830

2931
v0.3.7 (2024-04-08)

0 commit comments

Comments
 (0)