[英]Ansible - how to run Java jar with parameters?
I have a problem with ansible playbook.我对 ansible playbook 有问题。 I am trying to run a Java jar as a command.
我正在尝试将 Java jar 作为命令运行。 Whenever I run this directly on the virtual machine - it works all the time:
每当我直接在虚拟机上运行它时 - 它一直有效:
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
重要信息:安装必须从用户
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?找不到Java? I don't understand this.
我不明白这个。 Java is installed and working properly!
Java已安装并正常运行!
Can anyone help me with this?任何人都可以帮我解决这个问题吗?
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"
You should add your java address before "java".你应该在“java”之前添加你的java地址。 This problem may be occurs when using ssh too.
使用 ssh 时也可能出现此问题。 For example:
例如:
shell: /your_java_address_in_target_server/java -jar Installer20161018.jar -readImage Linux_x86-64_20161111.zip -installDir /opt/installPath/vf5511/instDir
#1. #1. make sure you "become_user" who has access to java #2.
确保您可以访问 java #2 的“become_user”。 In the .bash_profile, make sure you are setting the Java home path.
在 .bash_profile 中,确保您正在设置 Java 主路径。 #3.
#3. Before calling the java command, run .bash_profile to make sure the JDK path is set.
在调用 java 命令之前,运行 .bash_profile 以确保设置了 JDK 路径。 Eg: - name: unjar abc.jar shell: source ~/.bash_profile;
例如: - name: unjar abc.jar shell: source ~/.bash_profile; jar xvf abc.jar
jar xvf abc.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.