Reputation: 26084
I have a playbook with this task, among others:
- name: Compile and package
command: './mvnw clean package'
args:
chdir: "{{workdir}}"
But I get this error:
FAILED! => {"changed": true, "cmd": "./mvnw clean package", "delta": "0:00:00.003895", "end": "2016-12-29 21:59:16.121501", "failed": true, "rc": 1, "start": "2016-12-29 21:59:16.117606", "stderr": "Error: JAVA_HOME is not defined correctly.\n We cannot execute ", "stdout": "", "stdout_lines": [], "warnings": []}
If I access via SSH to the remote host and execute the same command, it works. JAVA_HOME
is defined, obviously, but it seems that Ansible can't detect it.
Upvotes: 0
Views: 1006
Reputation: 68559
When it says JAVA_HOME
is not defined, it likely means JAVA_HOME
is not defined.
First, when you login, you are using shell's interactive mode / login shell, when you use Ansible, you are using shell's non-interactive mode. Different rc-files are loaded for the two - refer to the "INVOCATION" section of man bash
or Bash Startup Files (it's similar for other shells, but I assume you are using Bash).
If JAVA_HOME
variable assignment is in the rc-files which run only in interactive mode, you will have a discrepancy. Move the definition to the proper place.
Second, also depending on the place where you set JAVA_HOME
- using shell
module instead of command
might load the proper definition file.
Just define the JAVA_HOME
for this task with environment
and do not rely on implicit inclusions..
Upvotes: 1