using a "when" for setting environment ?

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.

I think that's setting an environment variable called 'when' with a
value of 'use_apt_mirror'.