salt-ssh : 使用 python api 禁用 SSH 主机密钥检查

salt-ssh : Disable SSH Host Key Checking with python api

我正在使用 salt-ssh 和命令行,我可以使用选项 -i 来使用 'StrictHostKeyChecking'

(agent) [root@NODE ~]# salt-ssh  'af0abc4b-6980d-4fdd-ba63-192cb3d116be' test.ping
af0abc4b-6980d-4fdd-ba63-192cb3d116be:
    ----------
    retcode:
        254
    stderr:
    stdout:
        The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:
        The authenticity of host '10.10.10.10 (10.10.10.10)' can't be established.
        ECDSA key fingerprint is af:00:b8:ab:7a:3e:cd:06:9a:6c:36:e9:32:f0:a3:a4.
        Are you sure you want to continue connecting (yes/no)? 

(agent) [root@NODE ~]# salt-ssh -i --no-host-keys 'af0abc4b-6980d-4fdd-ba63-192cb3d116be' test.ping
af0abc4b-6980d-4fdd-ba63-192cb3d116be:
    True

但是当我想用 python api 做同样的事情时,我没有找到指定 -i 选项的方法所以可以做到。

这是我正在使用的 python 代码

from salt.client.ssh.client import SSHClient
salt = SSHClient()
salt.cmd('af0abc4b-6980d-4fdd-ba63-192cb3d116be', 'test.ping')
Out: 
{'af0abc4b-6980d-4fdd-ba63-192cb3d116be': {'retcode': 254,
  'stderr': '',
  'stdout': "The host key needs to be accepted, to auto accept run salt-ssh with the -i flag:\nThe authenticity of host '10.10.10.10 (10.10.10.10)' can't be established.\nECDSA key fingerprint is af:00:b8:ab:7a:3e:cd:06:9a:6c:36:e9:32:f0:a3:a4.\nAre you sure you want to continue connecting (yes/no)? "}}

如何使用 python 代码执行相同的操作??

我找到的唯一解决方案是在 $HOME/.ssh/config`.

中配置 StrictHostKeyChecking

示例 $HOME/.ssh/config

Host *
    StrictHostKeyChecking no

Host 10.10.10.15
   StrictHostKeyChecking no