Can you provide more detail with an example of a variable you are trying to pass?
As I'm not sure what you need to set, this could help?
Using set_fact: (example below), you can set a variable to be "something" based on a condition. So variable "DC" below, will become one of three variables "DC1, DC2 or DC3" depending on the domain of the server. You can swap out domain for any other ansible fact. Just use "{{ DC }}" in your playbook to reference and it should work in templates too.
I hope this helps.
---
- name: set fact/case example
hosts: localhost
tasks:
- set_fact:
one: hello
two: "{{ ansible_domain }}"
three: "{{ ansible_distribution_file_variety[3:6] }}"
DC: "{% if ansible_domain == 'eu-west-1.compute.internal' %}DC1\
{% elif ansible_domain == 'eu-west-2.compute.internal' %}DC2\
{% else %}DC3\
{% endif %}"
- name: one
debug:
msg: "{{ one }}"
- name: two
debug:
msg: "{{ two }}"
- name: three
debug:
msg: "{{ three }}"
- name: dc
debug:
msg: Your DC is {{ DC }}
- name: combine
debug:
msg: "{{ one }}-{{ two }}-{{ three }}-{{ DC }}"