# environment parameter

**URL:** <https://forum.ansible.com/t/environment-parameter/19643>\
**Category:** Ansible Project\
**Created:** [October 28, 2015, 8:00pm UTC](https://forum.ansible.com/t/environment-parameter/19643 "2015-10-28T20:00:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Matz](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Guy\_Matz](https://forum.ansible.com/u/Guy_Matz)\
**Post date:** [October 28, 2015, 8:00pm UTC](https://forum.ansible.com/t/environment-parameter/19643/1 "2015-10-28T20:00:30Z")

</div>

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;

```auto
{
  "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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 31, 2015, 7:44pm UTC](https://forum.ansible.com/t/environment-parameter/19643/2 "2015-10-31T19:44:23Z")

</div>

have you tried? environment: "{{wlst\_env}}"

---

<div class="post-metadata">

**Author:** ![Guy\_Matz](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Guy\_Matz](https://forum.ansible.com/u/Guy_Matz)\
**Post date:** [November 3, 2015, 4:28pm UTC](https://forum.ansible.com/t/environment-parameter/19643/3 "2015-11-03T16:28:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 3, 2015, 4:58pm UTC](https://forum.ansible.com/t/environment-parameter/19643/4 "2015-11-03T16:58:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guy\_Matz](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Guy\_Matz](https://forum.ansible.com/u/Guy_Matz)\
**Post date:** [November 3, 2015, 5:20pm UTC](https://forum.ansible.com/t/environment-parameter/19643/5 "2015-11-03T17:20:52Z")

</div>

🙂 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!!
