51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

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

使用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"
}
赞(0)
未经允许不得转载:工具盒子 » 通过Ansible对Centos5系统操作ping模块提示SyntaxError: invalid syntax解决