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 did a video demo of this on my YT 
channel: https://www.youtube.com/watch?v=NUGAQQ7p-Ho&t
And a gist of the code 
here: https://gist.github.com/dmccuk/63d8f668c96c95087144d2a09976b86f

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 }}"

On Wednesday, 22 December 2021 at 05:41:52 UTC [email protected] wrote:

> Can anyone help to for syntax or logic. Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/28ad9d1f-4fd1-4eaf-8bd4-6fede7f63e16n%40googlegroups.com.

Reply via email to