ansible執行playbook報Host Key checking

潇湘神剑發表於2024-11-12

報錯資訊:

(fastapi-ansible) root@WEB:/data/fastapi-ansible/project# ansible-playbook -i hosts ping.yaml

PLAY [Ping Test Playbook] *********************************************************************************************************************

TASK [Ping 檢測] ******************************************************************************************************************************
fatal: [10.11.16.8]: 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."}

PLAY RECAP ************************************************************************************************************************************
10.11.16.8             : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

解決辦法:

方式1、在hosts檔案中用ssh秘鑰

[user]
10.11.16.8 ansible_ssh_user=root ansible_ssh_port=32069 ansible_ssh_private_key_file=/root/.ssh/id_rsa

方式2、修改ansible配置檔案,禁用ssh秘鑰主機檢查

vim /etc/ansible/ansible.cfg

# uncomment this to disable SSH key host checking
host_key_checking = False

相關文章