是否有一种方法可以忽略由Ansible做出的SSH真实性检查?例如,当我刚刚安装了一个新服务器时,我必须回答这个问题:

GATHERING FACTS ***************************************************************
The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is xx:yy:zz:....
Are you sure you want to continue connecting (yes/no)?

我知道这通常是一个坏主意,但我将它合并到一个脚本中,该脚本首先在我的云提供商创建一个新的虚拟服务器,然后自动调用我的ansible playbook来配置它。我希望在脚本执行过程中避免任何人为干预。


当前回答

我知道这个问题已经得到了回答,这也是正确的,但只是想链接ansible文档,其中清楚地解释了何时以及为什么应该添加相应的检查:host-key-checking

其他回答

这是我在我的环境中使用的工作方式。我使用这张票的想法https://github.com/mitogen-hq/mitogen/issues/753

- name: Example play
  gather_facts: no
  hosts: all
  tasks:
    - name: Check SSH known_hosts for {{ inventory_hostname }}
      local_action: shell ssh-keygen -l -F {{ inventory_hostname }}
      register: checkForKnownHostsEntry
      failed_when: false
      changed_when: false
      ignore_errors: yes
    - name: Add {{ inventory_hostname }} to SSH known hosts automatically
      when: checkForKnownHostsEntry.rc == 1
      changed_when: checkForKnownHostsEntry.rc == 1
      local_action: 
         module: shell
         args: ssh-keyscan -H "{{ inventory_hostname }}" >> $HOME/.ssh/known_hosts

你可以在运行playbook时将它作为命令行参数传递:

ansible-playbook玩。yml——ssh-common-args='-o StrictHostKeyChecking=no'

使用名为validate_certs的参数来忽略ssh验证

- ec2_ami:
    instance_id: i-0661fa8b45a7531a7
    wait: yes
    name: ansible
    validate_certs: false
    tags:
      Name: ansible
      Service: TestService

通过这样做,它忽略了ssh验证过程

我知道这个问题已经得到了回答,这也是正确的,但只是想链接ansible文档,其中清楚地解释了何时以及为什么应该添加相应的检查:host-key-checking

您可以简单地告诉SSH自动接受新主机的指纹。只需添加

StrictHostKeyChecking=accept-new

到您的~/.ssh/config。它并没有完全禁用主机密钥检查,只是禁用了是否要向已知主机列表添加新指纹这个恼人的问题。如果已知机器的指纹发生了变化,您仍然会得到错误。

此策略还适用于ANSIBLE_HOST_KEY_CHECKING和其他将此参数传递给SSH的方式。