environment parameter

Hi! I’m trying to use the environment parameter in order to set JAVA_HOME for a task . . .

I have this in my vars file:

wlst_env:
JAVA_HOME: /opt/software/java/jdk1.6.0_30

and this in my tasks file:

  • include_vars: main.yml

  • debug: var=wlst_env

  • name: Call undeploy script
    command: “/opt/software/bea/wlserver_10.3/common/bin/wlst.sh /tmp/{{ wlst_repo }}/undeploy.py”
    environment: wlst_env

The debug us saying that wlst_env is set correctly;

{
  "var": {
    "wlst_env": {
      "JAVA_HOME": "/opt/software/java/jdk1.6.0_30"
    }
  },
 .
.
.
 "event": "Host OK"
}

but my “Call undeploy script” task fails with:
The JDK wasn’t found in directory /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64.
Please edit the startWebLogic.sh script so that the JAVA_HOME
variable points to the location of your JDK

Which makes me think that JAVA_HOME is not actually getting set! Any ideas what I’m doing wrong here?

Thanks a lot,

Guy

have you tried? environment: "{{wlst_env}}"

Thanks so much for your reply!! Adding the braces doesn’t seem to help:

  • debug: var=wlst_env

  • debug: msg={{ lookup(‘env’, ‘JAVA_HOME’) }}
    environment: “{{wlst_env}}”

yields:

ok: [bwi-jbmadm-g01] => {
“var”: {
“wlst_env”: {
“JAVA_HOME”: “/opt/software/java/jdk1.6.0_30”
}
}
}

ok: [bwi-jbmadm-g01] => {
“msg”: “/usr/lib/jvm/java-7-openjdk-amd64”
}

Any other thoughts? Thanks again!!

Guy

Bad test:
- lookup checks the env on the 'local' host not the target
- environment affects tasks, not lookups
- debug does not use an execution shell so environment is useless on it

:slight_smile: That was a bad test!! This looks better:

  • name: check env vars
    command: env
    environment: “{{wlst_env}}”
    register: env_out

  • debug: var=env_out

That shows the environment I was looking for, so I guess it was the quoted-curlies - i.e, “{{ wlst_env }}” - I needed! Thanks a lot!!