# using a "when" for setting environment ?

**URL:** <https://forum.ansible.com/t/using-a-when-for-setting-environment/24418>\
**Category:** Ansible Project\
**Created:** [May 8, 2017, 9:04am UTC](https://forum.ansible.com/t/using-a-when-for-setting-environment/24418 "2017-05-08T09:04:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Tan](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephen\_Tan](https://forum.ansible.com/u/Stephen_Tan)\
**Post date:** [May 8, 2017, 9:04am UTC](https://forum.ansible.com/t/using-a-when-for-setting-environment/24418/1 "2017-05-08T09:04:38Z")

</div>

Will this work?

environment:  
http\_proxy: “{{ apt\_mirror }}”  
when: use\_apt\_mirror

So, I only want to set the environment variable when the var “use\_apt\_mirror” is true. There is no obvious documentation to suggest that this won’t work.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [May 8, 2017, 6:40pm UTC](https://forum.ansible.com/t/using-a-when-for-setting-environment/24418/2 "2017-05-08T18:40:03Z")

</div>

I think that's setting an environment variable called 'when' with a  
value of 'use\_apt\_mirror'.
