【Ansible】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 <module>    (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



原文地址

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

(出处: 乐维_一站式运维监控管理平台)


相关文章
|
6月前
|
运维 Kubernetes 网络安全
Ansible自动化运维工具之主机管理与自定义配置文件(2)
Ansible自动化运维工具之主机管理与自定义配置文件(2)
|
6月前
|
运维 应用服务中间件 网络安全
Ansible自动化运维工具之解决SSH连接使用明文密码问题(4)
Ansible自动化运维工具之解决SSH连接使用明文密码问题(4)
|
缓存 Linux
yum安装ansible报错如何解决
本篇内容记录了yum安装ansible报错的解决方案。
1025 0
yum安装ansible报错如何解决
|
6月前
|
运维 搜索推荐 Shell
Ansible自动化运维工具之个性化定制SSH连接登录端口(3)
Ansible自动化运维工具之个性化定制SSH连接登录端口(3)
181 0
|
3月前
|
运维 监控 测试技术
ansible 自动化运维监控方案
本文介绍如何利用ansible实时或自动采集受控主机的信息
|
5月前
|
Shell API Docker
ansible api执行远程脚本结果中文乱码报错
ansible api执行远程脚本结果中文乱码报错
|
8月前
|
运维 监控
【运维知识进阶篇】Zabbix5.0稳定版详解10(Zabbix自动注册+Ansible自动部署,实现一条命令监控任意主机)
【运维知识进阶篇】Zabbix5.0稳定版详解10(Zabbix自动注册+Ansible自动部署,实现一条命令监控任意主机)
110 0
|
8月前
|
运维 Ubuntu 应用服务中间件
【运维知识进阶篇】Ansible自动化运维-Ansible安装与主机列表
【运维知识进阶篇】Ansible自动化运维-Ansible安装与主机列表
116 0
头疼:ansible坑之拷贝目录不报错,远程主机没有目录
头疼:ansible坑之拷贝目录不报错,远程主机没有目录
211 0
|
网络安全 数据安全/隐私保护
Ansible中的inventory主机清单(预祝你我有数不尽的鲜花和浪漫)
Ansible中的inventory主机清单(预祝你我有数不尽的鲜花和浪漫)
98 0
Ansible中的inventory主机清单(预祝你我有数不尽的鲜花和浪漫)