千家信息网

ansible all -m ping命令失败解决方法

发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,常用ansible命令查看组中的机器ansible list查看内存使用(shell模块)ansible -m command -a 'free -h'查看主机磁盘容量(command模块)ans
千家信息网最后更新 2025年02月03日ansible all -m ping命令失败解决方法

常用ansible命令

查看组中的机器

ansible  list

查看内存使用(shell模块)

ansible  -m command -a 'free -h'

查看主机磁盘容量(command模块)

ansible  -m shell -a 'df -h'

报错解决记录

ansible all -m ping 失败

执行上述命令,是检测被主机的存活状态时,出现如下报错信息:

"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)."

执行下面的命令显示更详细 的信息

ansible -m ping all -vvv

结果中有如下

 ESTABLISH SSH CONNECTION FOR USER: None

ansible连接被管主机(此处是websrv.internal.org)没有使用明确的用户名。因此,在ansible的配置文件/etc/ansible/hosts中修改如下:

websrv.internal.org ansible_user=test

此处的'test'是websrv.internal.org主机上的可登录用户,如果配置了公钥,则可以成功完成上述主机探测命令。回显如下:

websrv.internal.org | SUCCESS => {"changed": false, "ping": "pong"}
0