Unable to export CLASSPATH for localhost on Ansible on Linux Redhat

97 views
Skip to first unread message

Mohtashim S

unread,
Jul 13, 2021, 4:04:10 AM7/13/21
to Ansible Project

I get the below error while executing the shell command on ansible localhost

$ java utils.dbping ORACLE_THIN <dbhost>:<dbport>:<dbname> Error: Could not find or load main class utils.dbping

Inorder, to resolve this error i set the classpath like below:

export CLASSPATH=/web/playbooks/automation/libraries/com.bea.core.datasource6.jar

With this the java utils.dbping command works fine.

I try the same command in ansible on localhost as below:

47 - name: Check DB connection with DBPING
48   shell: "java utils.dbping ORACLE_THIN <dbhost>:<dbport>:<dbname>"
49   environment:
50      CLASSPATH: "/web/playbooks/automation/libraries/com.bea.core.datasource6.jar"
51      PATH: "/web/jdk1.8.0_291/bin"
52   delegate_to: localhost

But I get the below error indicating that the CLASSPATH was not set correctly.

02:57:43 failed: [remotehost7 -> localhost] => {"changed": true, "cmd": "java utils.dbping", "delta": "0:00:00.078752", "end": "2021-07-12 17:27:43.616820", "msg": "non-zero return code", "rc": 1, "start": "2021-07-12 17:27:43.538068", "stderr": "java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:382)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:418)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:351)\n\tat java.lang.Class.forName0(Native Method)\n\tat java.lang.Class.forName(Class.java:264)\n\tat utils.dbping.main(dbping.java:282)", "stderr_lines": ["java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver", "\tat java.net.URLClassLoader.findClass(URLClassLoader.java:382)", "\tat java.lang.ClassLoader.loadClass(ClassLoader.java:418)", "\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)", "\tat java.lang.ClassLoader.loadClass(ClassLoader.java:351)", "\tat java.lang.Class.forName0(Native Method)", "\tat java.lang.Class.forName(Class.java:264)", "\tat utils.dbping.main(dbping.java:282)"], "stdout": "\nError encountered:", "stdout_lines": ["", "Error encountered:"]}

I even tried CLASSPATH: "/web/playbooks/automation/libraries/com.bea.core.datasource6.jar:.:" but that too did not help.

I also tried java -cp option but still no luck.

I prefer to mention the CLASSPATH in ansible rather than in shell prompt along with ansible command.

Can you please suggest?

Dick Visser

unread,
Jul 13, 2021, 5:37:55 AM7/13/21
to ansible...@googlegroups.com
On Tue, 13 Jul 2021 at 10:04, Mohtashim S <mohta...@gmail.com> wrote:

You only provided the path to reach utils.dbping.
But your error now says:

java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

This is a different class missing.
Basically you need to provide ALL required paths in CLASSPATH.


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Mohtashim S

unread,
Jul 13, 2021, 12:24:34 PM7/13/21
to Ansible Project
Dick Hi,

Your suggestion helped!!

Thank you. 
Reply all
Reply to author
Forward
0 new messages