Saki's 研究记录

Ansible provisioning ERROR! Using a SSH password instead of a key is not poss...

字数统计: 275阅读时长: 1 min
2022/07/07

避免 Ansible 无法存取第一次登录的 Server

问题

最近使用 ansible批量管理服务器,这批机器都没在我本机登录过,在首次运行 ansible-playbook操作时出现报错:

1
fatal: [cache_01]: FAILED! => {"msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."}

原因

ssh在第一次连接的时候一般会提示输入 yes进行确认并把 ssh信息加入到 ~/.ssh/known_hosts文件中。因为报错的机器从未在本机登录过,所以并没有对应的 ssh信息才导致报错。

解决方法

方法1

ansible.cfg文件中更改下面的参数:

1
#host_key_checking = False 将#号去掉即可

方法2 (亲测有效)

添加环境变量,跳过 fingerprint检查, 例如我本机使用的是 zsh则编辑 ~/.zshrc文件,添加以下信息:

1
export ANSIBLE_HOST_KEY_CHECKING=False

引用

以上。

CATALOG
  1. 1. 避免 Ansible 无法存取第一次登录的 Server
    1. 1.1. 问题
    2. 1.2. 原因
    3. 1.3. 解决方法
      1. 1.3.1. 方法1
      2. 1.3.2. 方法2 (亲测有效)
    4. 1.4. 引用