我正在使用 SSH 用户名和密码设置运行标准 ansible (v2.3.1) 剧本。使用“-vvvv”设置时,我可以看到生成了这些 SSH 命令
EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s
-o StrictHostKeyChecking=no -o Port=2222
-o KbdInteractiveAuthentication=no
-o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
-o PasswordAuthentication=no -o User=dc_user -o ConnectTimeout=10
在上述情况下,'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey' 设置从哪里获取。我相信这些来自客户端 SSH 配置设置,但这正确吗?
我知道我可以通过在我的“ansaible.cfg”中定义它来覆盖 ssh 参数
[ssh_connection]
scp_if_ssh=True
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey
有人能给我解释一下吗?谢谢
答案1
我观察到这-o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
是硬编码的源代码
如果你覆盖ssh_args
到添加ansible.cfg
到-o PreferredAuthentications=publickey
ssh 命令行,但这不会替换-o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey
例子:
$ grep ssh_args /etc/ansible/ansible.cfg
#ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey
$ ansible rhel7a -m ping -vvvv |grep EXEC
<rhel7a> SSH: EXEC ssh -vvv -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/user/.ansible/cp/13dd447a86 rhel7a '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''