简体   繁体   English

“ ImportError:没有名为xhaus的模块” Python模块从ansible导入错误

[英]“ImportError: No module named xhaus” Python module importing error from ansible

I have one python script it was working if I run from my terminal directly, but the same script I am running using Ansible but at the time I am getting below error. 我有一个python脚本,如果我直接从终端运行,它将正常工作,但是使用Ansible运行的是同一脚本,但当时我遇到了以下错误。

Ansible command is: 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}}"

And command_result2.stderr is 并且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"

Please help me to resolve this. 请帮助我解决此问题。

Edit: Actually forgotten to say, the missing module(xhaus) is a JAR file and it is located in the same path where python script file is located. 编辑:实际上忘了说,缺少的模块(xhaus)是一个JAR文件,它位于python脚本文件所在的相同路径中。 Is anywhere I need to add that JAR to CLASSPATH? 我需要将该JAR添加到CLASSPATH的任何地方吗?

I personally try to use it and it work well, can you try this one: 我个人尝试使用它,并且效果很好,您可以尝试以下一种方法:

- name: Execute the script
  script: "/Path-to-local-system/installer.py -i -s -c"

play with it and adjust the parameters, refere this page for more help 玩耍并调整参数,请参阅此页面以获得更多帮助

Finally, I had fixed above problem with a little bit hack. 最后,我通过一点点修改解决了上述问题。 I had simply added sys.path.append('JAR location') line in my python script. 我只是在python脚本中添加了sys.path.append('JAR location')行。 Boom, its worked pretty well. 景气,效果很好。 Please let me know, if anyone know better solution. 如果有人知道更好的解决方案,请让我知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM