虚拟化容器,大数据,DBA,中间件,监控。

ansible解决python版本依赖

11 11月
作者:admin|分类:系统运维

ansible解决python版本依赖

ansible解决python版本依赖

  • ansible解决python版本依赖
    • 1.python版本问题会报如下错误
    • 2.排查思路

目前服务器的版本各不相同,有centos5 centos6 centos7,服务器版本不同python的版本也不同,因此会导致一些服务器执行批量命令失败

1.python版本问题会报如下错误

[WARNING]: Unhandled error in Python interpreter discovery for host 192.168.3.50: No JSON object could be decoded
[WARNING]: Platform linux on host 192.168.3.50 is using the discovered Python interpreter at /usr/bin/python, but
future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
192.168.3.50 | FAILED! => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: false,
“module_stderr”: “Shared connection to 192.168.3.50 closed.\r\n”,
“module_stdout”: " File “/root/.ansible/tmp/ansible-tmp-1607391445.82-4128297-83808946260841/AnsiballZ_ping.py”, line 72\r\n with open(args_path, ‘rb’) as f:\r\n ^\r\nSyntaxError: invalid syntax\r\n",
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,
“rc”: 1
}
在这里插入图片描述

这个就是典型的语法错误,语法错误是由于python版本太低的问题导致的

2.排查思路

排查思路:首先ssh到失败的服务器查询python版本,如果是2.7一下那么只需要将python版本升级为2.7或者以上即可解决问题
但是这里不建议直接去升级python版本,可以在一台新的机器上将python2.7安装好,然后打包到有问题的机器上上利用ansible_python_interpreter这个变量指定python的版本即可


vim /etc/ansible/hosts

192.168.3.50 ansible_python_interpreter=/usr/local/python2.7/bin/python2.7

再次执行ping命令即可成功

192.168.3.50 | SUCCESS => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: false,
“ping”: “pong”
}

浏览640 评论0
返回
目录
返回
首页
ansible设置主机并行次数---使得ansible输出与主机清单顺序一致 综合案例:利用ansible常用七种模块实现备份系统的部署及告警(十一)