"ImportError: No module named xhaus" Python module importing error from ansible
"ImportError: No module named xhaus" Python module importing error from ansible
我有一个 python 脚本,如果我直接从我的终端 运行 它可以工作,但是我正在 运行 使用 Ansible 的同一个脚本,但当时我得到低于错误。
Ansible 命令是:
- name: run installer command 2
command: "{{auto_inst_loc}}/installer.py -i -s -c"
register: command_result2
- debug: msg="{{command_result2.stdout}}"
- debug: msg="{{command_result2.stderr}}"
而command_result2.stderr是
"msg": "Traceback (most recent call last):\n
File \"../scripts/Lib/soa/automation/containerManager.py\", line 9, in
<module>\n from apicontainer import constants, common\n File
\"/opt/akana_sw/sm8/scripts/Lib/soa/automation/apicontainer/common.py\",
line 10, in <module>\n from com.xhaus.jyson import JysonCodec as
json\nImportError: No module named xhaus"
请帮我解决这个问题。
编辑:其实忘了说,缺少的模块(xhaus)是一个JAR文件,它位于python脚本文件所在的同一路径。有什么地方需要将该 JAR 添加到 CLASSPATH 中吗?
我亲自试过,效果很好,你可以试试这个吗:
- name: Execute the script
script: "/Path-to-local-system/installer.py -i -s -c"
使用它并调整参数,请参考此 page 以获得更多帮助
最后,我用一点技巧解决了上述问题。我只是在 python 脚本中添加了 sys.path.append('JAR location') 行。繁荣,它工作得很好。如果有人知道更好的解决方案,请告诉我。
我有一个 python 脚本,如果我直接从我的终端 运行 它可以工作,但是我正在 运行 使用 Ansible 的同一个脚本,但当时我得到低于错误。
Ansible 命令是:
- name: run installer command 2
command: "{{auto_inst_loc}}/installer.py -i -s -c"
register: command_result2
- debug: msg="{{command_result2.stdout}}"
- debug: msg="{{command_result2.stderr}}"
而command_result2.stderr是
"msg": "Traceback (most recent call last):\n
File \"../scripts/Lib/soa/automation/containerManager.py\", line 9, in
<module>\n from apicontainer import constants, common\n File
\"/opt/akana_sw/sm8/scripts/Lib/soa/automation/apicontainer/common.py\",
line 10, in <module>\n from com.xhaus.jyson import JysonCodec as
json\nImportError: No module named xhaus"
请帮我解决这个问题。
编辑:其实忘了说,缺少的模块(xhaus)是一个JAR文件,它位于python脚本文件所在的同一路径。有什么地方需要将该 JAR 添加到 CLASSPATH 中吗?
我亲自试过,效果很好,你可以试试这个吗:
- name: Execute the script
script: "/Path-to-local-system/installer.py -i -s -c"
使用它并调整参数,请参考此 page 以获得更多帮助
最后,我用一点技巧解决了上述问题。我只是在 python 脚本中添加了 sys.path.append('JAR location') 行。繁荣,它工作得很好。如果有人知道更好的解决方案,请告诉我。