Ansible - how to run Java jar with parameters?

Viewed 15895

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:

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

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!

Can anyone help me with this?

3 Answers

You should add your java address before "java". This problem may be occurs when using ssh too. 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. make sure you "become_user" who has access to java #2. In the .bash_profile, make sure you are setting the Java home path. #3. Before calling the java command, run .bash_profile to make sure the JDK path is set. Eg: - name: unjar abc.jar shell: source ~/.bash_profile; jar xvf abc.jar

Related