# Is there a way to set environment variables with conditionals?

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-set-environment-variables-with-conditionals/19667>\
**Category:** Ansible Project\
**Created:** [November 1, 2015, 3:14pm UTC](https://forum.ansible.com/t/is-there-a-way-to-set-environment-variables-with-conditionals/19667 "2015-11-01T15:14:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Schmitt](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@Christian\_Schmitt](https://forum.ansible.com/u/Christian_Schmitt)\
**Post date:** [November 1, 2015, 3:14pm UTC](https://forum.ansible.com/t/is-there-a-way-to-set-environment-variables-with-conditionals/19667/1 "2015-11-01T15:14:14Z")

</div>

Hello, currently we have a site which needs a openvpn connection and some proxy variables while connection via ansible.

Is there a way to set a environment variable only when a ansible condition is met? If we connect to the connection we specify a variable called remote=true so we only need to set the env variables when the condition is met.

---

<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 1, 2015, 9:39pm UTC](https://forum.ansible.com/t/is-there-a-way-to-set-environment-variables-with-conditionals/19667/2 "2015-11-01T21:39:06Z")

</div>

assuming the environment you want to set is in a var named 'myenvdict':

environment: "{{ remote|ternary(myenvdict, {}) }}"
