Ansible Using a SSH password instead of a key is not possible because Host Key接続エラーの解決方法

環境

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Red Hat Enterprise Linux release 9.2 (Plow)
Ansible 2.14.2
Python 3.11.2
Red Hat Enterprise Linux release 9.2 (Plow) Ansible 2.14.2 Python 3.11.2
Red Hat Enterprise Linux release 9.2 (Plow)
Ansible 2.14.2
Python 3.11.2

実行コマンド
ansible $ansible-playbook -i /etc/ansible/hosts test.yml -k

警告メッセージが表示されます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
PLAY [Ansibleテスト] ****************************************************************************************************************************************
TASK [チェックディレクトリ] *********************************************************************************************************************************
fatal: [192.168.213.129]: 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 **************************************************************************************************************************************************
192.168.213.129 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
PLAY [Ansibleテスト] **************************************************************************************************************************************** TASK [チェックディレクトリ] ********************************************************************************************************************************* fatal: [192.168.213.129]: 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 ************************************************************************************************************************************************** 192.168.213.129 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
PLAY [Ansibleテスト] ****************************************************************************************************************************************

TASK [チェックディレクトリ] *********************************************************************************************************************************
fatal: [192.168.213.129]: 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 **************************************************************************************************************************************************
192.168.213.129            : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

方法1
# vi /etc/ansible/ansible.cfg
以下の設定を記載する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
[ssh_connection] ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

説明
StrictHostKeyChecking=no
ホストのデータベースファイル(デフォルトでは~/.ssh/known_hosts)に存在しないときに確認なしに接続する。fingerprintは確認なしにホストのデータベースファイルに記録されていく。

UserKnownHostsFile=/dev/null
ホストのデータベースファイル。

方法2
#vi ~/.ssh/config
以下の内容を記載する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Host 192.168.213.*
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Host 192.168.213.* StrictHostKeyChecking no UserKnownHostsFile=/dev/null
Host 192.168.213.*
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null

説明
ansibleを実行するControl MachineのユーザのSSH設定で、fingerprintのチェックを行わないようにする。

Ansible

Posted by arkgame