variables and number in conditionals

Hi,
I’ve some misunderstanding regarding conditionals on variables or number.
By example, within a role we’re using some prompt to defined some variables.

-name: “server_domain”
prompt: “Choose server?\n1- Server1\n2- Server2\n3…”
default: “1”
private: no

In another role, we’ll defined variables regarding this response.

-name: “Server”
set_fact:
domain: “{{ ‘local.com’}}”
when: server_domain == 1

It doesn’t run but it’s seems to run when I write
when: server_domain == “1”
It’s a number and not a variable. So, is it right?
Could you please explain me what is the correct way?

Best regards, H

Convert the variable to integer

      when: server_domain|int == 1

Use "type_debug" filter to display the type of the variable. For
example

    - set_fact:
        server_domain: "1" # AnsibleUnicode
    - debug:
        msg: "{{ server_domain|type_debug }}"
    - debug:
        msg: OK
      when: server_domain|int == 1

    - set_fact:
        server_domain: 1 # Integer
    - debug:
        msg: "{{ server_domain|type_debug }}"
    - debug:
        msg: OK
      when: server_domain == 1

Thanks a lot for your explanation and feedback…
The debug shows me an unicode variable and piping to int the conditionals resolved my issue.
It’s not an easy subject and I’m looking for good stuff to read.

Do you have any good tips?
Regards,
H