# setting environment variables

**URL:** <https://forum.ansible.com/t/setting-environment-variables/27052>\
**Category:** Ansible Project\
**Created:** [March 20, 2018, 12:27pm UTC](https://forum.ansible.com/t/setting-environment-variables/27052 "2018-03-20T12:27:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danish09](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@danish09](https://forum.ansible.com/u/danish09)\
**Post date:** [March 20, 2018, 12:27pm UTC](https://forum.ansible.com/t/setting-environment-variables/27052/1 "2018-03-20T12:27:40Z")

</div>

Hi,

I know the solution to this topic has been posted many times and I have tried searching through google and other forums including the ansible docs but unfortunately, nothing seems to be working for me. Please provide your feedback and help me with the solution. Also please let me know if you need any further information.

I am trying to create a playbook to download and install jenkins from a war file and so installing java from the source file as a pre-requisite.

I check for the presence of Java and if not found, go on to download and install java from source and then registering the env variable JAVA\_HOME and adding the java binary onto my PATH. However, the environment variable part is frustratingly not working for me.

I initially started out with using the shell module to source /etc/profile using /bin/bash, but that didnt work. Read more and found out about environment keyword. As part of my playbook, I create a user jenkins\_user and then download the jenkins war file and try to run with the above defined env variables. unfortunately, it is not working. However, I am not sure I am doing this the correct way as I keep getting failures and the latest is that ‘java’ cannot be found by newly created jenkins\_user.

Pasted below is all my code.

`playbook.yaml`

`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 20, 2018, 1:31pm UTC](https://forum.ansible.com/t/setting-environment-variables/27052/2 "2018-03-20T13:31:21Z")

</div>

as you have it there, the `environment` keyword ONLY affects the  
get\_url task, I would add it to the include so all included tasks  
inherit it or put all tasks in install\_java in a block that has the  
environment keyword attached to it.

---

<div class="post-metadata">

**Author:** ![danish09](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@danish09](https://forum.ansible.com/u/danish09)\
**Post date:** [March 20, 2018, 3:27pm UTC](https://forum.ansible.com/t/setting-environment-variables/27052/3 "2018-03-20T15:27:33Z")

</div>

Thank you for responding to me. I am stuck now at some silly mistake of mine in that playbook. I will come back to your suggestion as soon as I correct the error.

Thanks for your advise again.

---

<div class="post-metadata">

**Author:** ![danish09](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@danish09](https://forum.ansible.com/u/danish09)\
**Post date:** [March 23, 2018, 4:24pm UTC](https://forum.ansible.com/t/setting-environment-variables/27052/4 "2018-03-23T16:24:20Z")

</div>

Thank you very much. Your suggestion is working perfect.
