bash Ansible - 如何使用参数运行 Java jar?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44325507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ansible - how to run Java jar with parameters?
提问by Zibi Smough
I have a problem with ansible playbook. I am trying to run a Java jar as a command. Whenever I run this directly on the virtual machine - it works all the time:
我对 ansible playbook 有问题。我正在尝试将 Java jar 作为命令运行。每当我直接在虚拟机上运行它时 - 它一直有效:
java -jar Installer20161018.jar -readImage Linux_x86-64_20161111.zip -installDir /opt/installPath/vf5511/instDir
important information:the installation HAS to be run from user vf5511
, and his home
folder is /opt/installPath/vf5511
重要信息:安装必须从 user 运行vf5511
,他的home
文件夹是/opt/installPath/vf5511
But when trying to write a playbook and run it - it gets all wrong.
但是当试图编写剧本并运行它时 - 它全都出错了。
This is the playbook:
这是剧本:
---
- hosts: webmwc10
become: yes
become_user: wm5511
become_method: sudo
tasks:
- name: installing server
shell: java -jar Installer20161018.jar -readImage Linux_x86-64_20161111.zip -installDir /opt/installPath/vf5511/instDir
When I run the playbook, I get an error:
当我运行剧本时,我收到一个错误:
"rc": 127,
"start": "2017-06-02 09:21:31.931049",
"stderr": "/bin/sh: java: command not found",
"stderr_lines": [
"/bin/sh: java: command not found"
],
"stdout": "",
"stdout_lines": []
Java not found? I don't understand this. Java is installed and working properly!
找不到Java?我不明白这个。Java 已安装并正常运行!
Can anyone help me with this?
谁能帮我这个?
回答by Praveen Raj Kumar
Run below commands on your target server to rule out Java issues
在目标服务器上运行以下命令以排除 Java 问题
which java
java -version
Upon successful results add quotes to your shell command like below and run the playbook again.
成功后,将引号添加到您的 shell 命令中,如下所示,然后再次运行剧本。
shell: "java -jar Installer20161018.jar -readImage Linux_x86-64_20161111.zip -installDir /opt/installPath/vf5511/instDir"
回答by ahmadi morteza ali
You should add your java address before "java". This problem may be occurs when using ssh too. For example:
你应该在“java”之前添加你的java地址。使用 ssh 时也可能出现此问题。例如:
shell: /your_java_address_in_target_server/java -jar Installer20161018.jar -readImage Linux_x86-64_20161111.zip -installDir /opt/installPath/vf5511/instDir