使用ansible执行ping模块时报错:

[root@localhost ansible]$ ansible -i hosts_互联网平台监测点 国内设备__112.5.26.5 -m ping
[WARNING]: Unhandled error in Python interpreter discovery for host 国内设备__112.5.26.5: No JSON object could be decoded
[WARNING]: Platform linux on host 国内设备__112.5.26.5 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.
国内设备__112.5.26.5 | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "module_stderr": "Shared connection to 112.5.26.5 closed.\r\n", 
    "module_stdout": "  File \"/root/.ansible/tmp/ansible-tmp-1667977331.42-2212-102626283714939/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
}

解决办法

因Centos5默认python-2.4.3版本过低,需要升级python至2.7.5及以上版本。

[root@localhost ~]# cat /etc/redhat-release
CentOS release 5.11 (Final)
[root@localhost ~]# /usr/bin/python --version
Python 2.7.9
升级效果
[root@localhost ansible]$ ansible -i hosts_互联网平台监测点 国内设备__112.5.26.5 -m ping
国内设备__112.5.26.5 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}
END

本文标题:通过Ansible对Centos5系统操作ping模块提示SyntaxError: invalid syntax解决

本文作者:宇宙最帅的男人

本文链接:https://lolicp.com/linux/202209465.html

版权声明:转载或者引用本文内容请注明来源及原作者,本文著作权归作者 (宇宙最帅的男人) 所有。

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

最后修改:2022 年 11 月 09 日
如果觉得我的文章对你有用,请随意赞赏