# variables and number in conditionals

**URL:** <https://forum.ansible.com/t/variables-and-number-in-conditionals/33930>\
**Category:** Ansible Project\
**Created:** [September 30, 2020, 1:41pm UTC](https://forum.ansible.com/t/variables-and-number-in-conditionals/33930 "2020-09-30T13:41:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hieronymus](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hieronymus/32/1624_2.png) [@hieronymus](https://forum.ansible.com/u/hieronymus)\
**Post date:** [September 30, 2020, 1:41pm UTC](https://forum.ansible.com/t/variables-and-number-in-conditionals/33930/1 "2020-09-30T13:41:51Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [September 30, 2020, 6:37pm UTC](https://forum.ansible.com/t/variables-and-number-in-conditionals/33930/2 "2020-09-30T18:37:36Z")

</div>

Convert the variable to integer

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: server\_domain|int == 1

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

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server\_domain: "1" # AnsibleUnicode  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ server\_domain|type\_debug }}"  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: OK  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: server\_domain|int == 1

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server\_domain: 1 # Integer  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ server\_domain|type\_debug }}"  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: OK  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: server\_domain == 1

---

<div class="post-metadata">

**Author:** ![hieronymus](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hieronymus/32/1624_2.png) [@hieronymus](https://forum.ansible.com/u/hieronymus)\
**Post date:** [October 1, 2020, 7:55am UTC](https://forum.ansible.com/t/variables-and-number-in-conditionals/33930/3 "2020-10-01T07:55:45Z")

</div>

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
