AnsibleでSSH接続¶
エラーと対処¶
パスワード指定でSSH接続する際にエラー(ERROR! SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh)となる¶
$ ansible foo -i ./hosts -u root -k -m ping
SSH password: ********
foo | UNREACHABLE! => {
"changed": false,
"msg": "ERROR! SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh",
"unreachable": true
}
同じコマンドラインでパスワードではなく鍵認証で接続すると
$ ansible foo -i ./hosts -m ping
foo | SUCCESS => {
"changed": false,
"ping": "pong"
}
と正常に接続可能というものです。
回避策:環境変数ANSIBLE_SCP_IF_SSH=yを設定¶
$ ANSIBLE_SCP_IF_SSH=y ansible foo -i ./hosts -u root -k -m ping
SSH password: ********
foo | SUCCESS => {
"changed": false,
"ping": "pong"
}
/etc/ansible/ansible.cfgに追記でも可
[ssh_connection] scp_if_ssh = True