Ansible 连接主机显示报错的处理方案

一、在ansible安装完毕后一般需要以SSH的方式连接到需要进行管理的目标主机,一开始遇到了如下问题:

192.168.15.4 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
"unreachable": true
}
192.168.15.55 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
"unreachable": true

原因分析:
没有在ansible管理节点(即安装ansible的节点)上添加目标节点(即需要管理的节点)的ssh认证信息。

解决步骤:
1:管理节点生成SSH-KEY

ssh-keygen

成功后在~/.ssh/路径下将生成ssh密钥文件:id_rsa及id_rsa.pub
2:添加目标节点的SSH认证信息

ssh-copy-id root@目标节点IP

这里root是在目标节点上登录的用户,@符号后面接目标节点IP即可,之后会提示输入目标节点root用户密码,输入即可。
添加认证信息后,目标节点主机的~/.ssh/目录下将会出现一个authorized_keys文件,里面包含了ansible管理节点的公钥信息,可以检查一下是否存在。
3:在确定目标主机的SSH认证信息都已正确添加且目标主机的~/.ssh/目录都存在管理节点的公钥信息后,再执行之前出错的ansible ping指令:

#ansible -m ping all

192.168.15.4 | SUCCES对之前未连接的主机进行连结时报错如下:S => {
    "changed": false, 
    "ping": "pong"
}
192.168.15.55 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

二、对之前未连接的主机进行连结时报错如下:

[root@puppet ~]# ansible webservers -m command -a 'ls ~' -k
SSH password:
192.168.15.10 | FAILED | rc=0 >>
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.

解决步骤:
修改ansible.cfg文件

vi /etc/ansible/ansible.cfg

找到以下行,让host_key_checking=False这行生效

uncomment this to disable SSH key host checking
host_key_checking = False

三、ansible requires a json module, none found!

SSH password:192.168.15.123 | FAILED >> { "failed": true, "msg": "Error: ansible requires a json module, nonefound!", "parsed": false}

解决步骤:
python版本过低,要不升级python要不就升级安装python-simplejson。yum install -y python-simplejson

四、第一次系统初始化运行生成本机ansible用户key时报错

failed: [127.0.0.1] =>{"checksum": "f5f2f20fc0774be961fffb951a50023e31abe920","failed": true}msg: Aborting, target uses selinux but pythonbindings (libselinux-python) aren't installed!FATAL: all hosts have already failed –aborting

解放步骤:

yum install libselinux-python -y

五、使用命令报错

·····Traceback (most recent call last): File "/usr/bin/ansible", line 197, in (runner, results) = cli.run(options, args) File "/usr/bin/ansible", line 163, in run extra_vars=extra_vars, File "/usr/lib/python2.6/site-packages/ansible/runner/init.py", line 233, in init cmd = subprocess.Popen(['ssh','-o','ControlPersist'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) File "/usr/lib64/python2.6/subprocess.py", line 639, in init errread, errwrite) File "/usr/lib64/python2.6/subprocess.py", line 1228, in _execute_child raise child_exceptionOSError: [Errno 2] No such file or directory

解决步骤:

yum install openssh-clients

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/9774

(0)
郭靖的头像郭靖
上一篇 2023年9月27日 下午7:43
下一篇 2023年10月7日 下午7:52

相关推荐

  • 安装linux/Centos系统出现An Unknown Error Has Occurred报错原因和解决方法

    今天在给一个客户重装系统的时候出现: An Unknown Error Has OccurredThis program has encountered an unknown error. You may report the buy below or quit the program. This program has encountered an unk…

    2024年1月22日
    1.9K00
  • 使用Powershell管理Windows计划任务

    在Windows系统中,我们经常使用Schedule Task来配置计划任务,来完成需要一段时间内重复完成的操作。Windows Schedule Task与Linux的Cron任务管理系统极为相似,都用于管理定时任务,但是前者大多数人都是以图形化操作为主,Powershell的出现将会改变这种情况。使用Powershell管理Schedule Task会事…

    2023年9月26日
    1.6K00
  • Windows挂载虚拟磁盘VHD/VHDX文件

    挂载VHD/VHDX 打开磁盘工具 WIN+R弹出运行窗口,输入:diskmgmt.msc命令,回车确认弹出磁盘管理工具 附加VHD/VHDX文件 可以看到已经添加到系统中,接下来就可以进行初始化操作 在系统中操作 打开我的电脑,可以发现多了一块磁盘 这个就是我们附加的vhdx文件。此时,已经可以对改vhdx文件进行操作了 分离vhdx

    2022年7月14日
    2.0K00
  • Git:合并多个commit 的高级技巧

    前言 在我们的日常项目开发中,git commit -m 无疑是使用最频繁的指令,这也造成了大量的commit 在我们的分支上。这样常常会带来分支过长、版本过多的问题。 正文 想要解决这个问题,我们通常会对commit 进行合并。 当我们发现两个commit 或多个commit 存在很强的关联性、并且几个commit 加起来也可以成为一个完整的描述的时候,就…

    2023年3月15日
    1.6K00
  • Windows server 2008 R2 服务报错14001解决方案

    错误 14001:因为应用程序的并行配置不正确 有关详细信息 请参阅应用程序事件日志 或使用命令行 sxstrace.exe 工具 今日通过服务管理器重新启动mysql服务时发现报错14001,解决方案如下: 打开左下角服务管理器,点击功能,然后添加功能,添加 Framework 3.51全部功能,这样就可以去服务管理器中启动服务了!!!

    2022年11月22日
    1.5K00

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信