add the user_known_hosts_file option

This commit is contained in:
Rui Lopes 2025-03-11 08:56:23 +00:00
parent d974206df0
commit 7dab8c8b56
No known key found for this signature in database

View file

@ -214,6 +214,17 @@ options:
cli:
- name: private_key_file
option: "--private-key"
user_known_hosts_file:
description:
- Path to the user known hosts file.
- Used to verify the ssh hosts keys.
type: string
default: ~/.ssh/known_hosts
ini:
- section: paramiko_connection
key: user_known_hosts_file
vars:
- name: ansible_paramiko_user_known_hosts_file
wsl_distribution:
description:
- WSL distribution name
@ -457,10 +468,10 @@ class Connection(ConnectionBase):
if self._log_channel is not None:
ssh.set_log_channel(self._log_channel)
self.keyfile = os.path.expanduser('~/.ssh/known_hosts')
self.keyfile = os.path.expanduser(self.get_option('user_known_hosts_file'))
if self.get_option('host_key_checking'):
for ssh_known_hosts in ('/etc/ssh/ssh_known_hosts', '/etc/openssh/ssh_known_hosts'):
for ssh_known_hosts in ('/etc/ssh/ssh_known_hosts', '/etc/openssh/ssh_known_hosts', self.keyfile):
try:
ssh.load_system_host_keys(ssh_known_hosts)
break