# Register variable numerical comparisons

**URL:** <https://forum.ansible.com/t/register-variable-numerical-comparisons/13887>\
**Category:** Ansible Project\
**Created:** [November 12, 2013, 5:50am UTC](https://forum.ansible.com/t/register-variable-numerical-comparisons/13887 "2013-11-12T05:50:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gonzalo\_Servat](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gonzalo\_Servat](https://forum.ansible.com/u/Gonzalo_Servat)\
**Post date:** [November 12, 2013, 5:50am UTC](https://forum.ansible.com/t/register-variable-numerical-comparisons/13887/1 "2013-11-12T05:50:53Z")

</div>

Hi All,

I’ve seen [some examples](http://www.ansibleworks.com/docs/playbooks_conditionals.html#register-variables) of using the shell module with register, but I can’t find any that allow a numerical comparison to be made on stdout. For example:

- hosts: all  
gather\_facts: False  
tasks:

- name: Get file count  
shell: ls /tmp | wc -l  
register: filecount

- name: Show a debug message  
debug: msg=“{{ inventory\_hostname }}”  
when: filecount.stdout \> 100

I am not trying to implement monitoring with Ansible 🙂 It is a one-off operation and I’m trying to just print a message if the output from wc is \> a number. I assume that because filecount.stdout is a string, the comparison fails, but how can I convert stdout to an integer?

- Gonzalo

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [November 12, 2013, 5:52am UTC](https://forum.ansible.com/t/register-variable-numerical-comparisons/13887/2 "2013-11-12T05:52:41Z")

</div>

try using the 'int' filter, i.e.,

&nbsp;&nbsp;&nbsp;when: filecount.stdout|int \> 100

Kahlil (Kal) Hodgson GPG: C9A02289  
Head of Technology (m) +61 (0) 4 2573 0382  
DealMax Pty Ltd (w) +61 (0) 3 9008 5281

Suite 1415  
401 Docklands Drive  
Docklands VIC 3008 Australia

"All parts should go together without forcing. You must remember that  
the parts you are reassembling were disassembled by you. Therefore,  
if you can't get them together again, there must be a reason. By all  
means, do not use a hammer." -- IBM maintenance manual, 1925

---

<div class="post-metadata">

**Author:** ![Gonzalo\_Servat](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gonzalo\_Servat](https://forum.ansible.com/u/Gonzalo_Servat)\
**Post date:** [November 12, 2013, 5:58am UTC](https://forum.ansible.com/t/register-variable-numerical-comparisons/13887/3 "2013-11-12T05:58:01Z")

</div>

Ah, thanks Kahlil 🙂

- Gonzalo
