# conditionals

**URL:** <https://forum.ansible.com/t/conditionals/29862>\
**Category:** Ansible Project\
**Created:** [March 11, 2019, 7:50pm UTC](https://forum.ansible.com/t/conditionals/29862 "2019-03-11T19:50:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Agnitsch](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@Jeffrey\_Agnitsch](https://forum.ansible.com/u/Jeffrey_Agnitsch)\
**Post date:** [March 11, 2019, 7:50pm UTC](https://forum.ansible.com/t/conditionals/29862/1 "2019-03-11T19:50:57Z")

</div>

Trying to do a conditional that when my inventory host name once converted to a string is greater than a number

Inventory file  
server1  
server2  
server3 -  
…  
…  
…  
…  
…

server205

this is the important parts of the role

- name: vmotion {{ inventory\_hostname }}  
vmware\_vmotion:  
hostname: “{{ vcenter\_hostname }}”  
username: "{{ vcenter\_username }}  
password: “{{ vcenter\_password }}”  
vm\_name: “{{ inventory\_hostname }}”  
destination\_datastore: “TP1”  
when: “`(inventory_hostname | regex_replace('.*([0-9]+).*', '\\1') | int) > 150`”  
delegate\_to: localhost

- name: vmotion {{ inventory\_hostname }}  
vmware\_vmotion:  
hostname: “{{ vcenter\_hostname }}”  
username: “{{ vcenter\_username }}@scriptpro.com”  
password: “{{ vcenter\_password }}”  
vm\_name: “{{ inventory\_hostname }}”  
destination\_datastore: “TP2”  
when: “`(inventory_hostname | regex_replace('.*([0-9]+).*', '\\1') | int) 180`”  
delegate\_to: localhost

it fails with

": “The conditional check ‘`(inventory_hostname | regex_replace('.*([0-9]+).*', '\\1') | int) is even`’ failed. The error was: template error while templating string: unexpected char u’`' at 6. String: {% if `(inventory\_hostname | regex\_replace(‘._([0-9]+)._’, ‘\1’) | int) is even` %} True {% else %} False {% endif %}\n\nThe error appears to have been in ‘/etc/ansible/roles/vmotion\_app/tasks/main.yml’: line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n—\n- name: vmotion {{ inventory\_hostname }}\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}

any thoughts are appreciated

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [March 11, 2019, 8:06pm UTC](https://forum.ansible.com/t/conditionals/29862/2 "2019-03-11T20:06:27Z")

</div>

Hi Jeffrey,
