Is there a way to set environment variables with conditionals?

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.

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

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