首页 > 解决方案 > Shell 模块失败但原始模块工作.. 在 Ansible

问题描述

我的客户端机器是 5.11 和 python 版本 2.7 但它仍然失败

root@00047BLRSANDEEPC:/mnt/e/Ansible-project/Solarwind/systems_swiagent_install/tests# ansible -i hosts all -m shell -a "cat /etc/redhat-release"
10.XX.XX.XX | FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to 10.XX.XX.XX closed.\r\n",
    "module_stdout": "  File \"/root/.ansible/tmp/ansible-tmp-1561087764.46-1054359176771/AnsiballZ_command.py\", line 39\r\n    with open(module, 'wb') as f:\r\n            ^\r\nSyntaxError: invalid syntax\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

工作 -->

root@00047BLRSANDEEPC:/mnt/e/Ansible-project/Solarwind/systems_swiagent_install/tests# ansible -i hosts all -m raw -a "cat /etc/redhat-release"
10.XX.XX.XX | CHANGED | rc=0 >>
CentOS release 5.11 (Final)
Shared connection to 10.XX.XX.XX closed.

标签: ansibleansible-template

解决方案


原始模块不需要安装 python。因此,它提供了所需的输出。
运行 shell 命令时,无法在该远程主机上检测到 python。尝试在 PATH 变量中设置 python 可执行文件。ansible -i hosts all -m shell -a "export PATH=<python_installed_location>:$PATH && cat /etc/redhat-release"

如果可行,请尝试在 PATH 变量中设置 python,然后运行所有命令。


推荐阅读