# How best to compare filesystem size against another number?

**URL:** <https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048>\
**Category:** Get Help\
**Tags:** templating, linux\
**Created:** [July 23, 2025, 7:47pm UTC](https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048 "2025-07-23T19:47:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tacocat](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@tacocat](https://forum.ansible.com/u/tacocat)\
**Post date:** [July 23, 2025, 7:47pm UTC](https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048/1 "2025-07-23T19:47:47Z")

</div>

Hi there!

I’m trying to get the size of a filesystem (/opt in this case) and ensure it is larger than another number (3Gb). Here’s what I have in my test playbook:

```auto
---
- name: Assert that /opt has more than 3GB available
  hosts: localhost
  gather_facts: yes
  tasks:

    - name: Set available bytes for /opt
      set_fact:
        opt_available_bytes: "{{ item.size_available | int }}"
      loop: "{{ ansible_mounts }}"
      when: item.mount == '/opt'

    - name: Assert /opt has more than 3GB free
      assert:
        that:
          - opt_available_bytes > (3 * 1024 * 1024 * 1024)
        fail_msg: "/opt has less than 3GB free ({{ opt_available_bytes }} bytes)"
        success_msg: "/opt has sufficient space ({{ opt_available_bytes }} bytes)"

```

But when I run it, I get:

`'>' not supported between instances of 'AnsibleUnsafeText' and 'int'. '>' not supported between instances of 'AnsibleUnsafeText' and 'int'"}`

I’m sure it’s something stupid that I’m doing but I thought the “{{ item.size\_available | int }}” sets that fact to be an int but apparently not. What is the right way to do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [July 23, 2025, 8:08pm UTC](https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048/2 "2025-07-23T20:08:23Z")

</div>

Use type casting on consumption, 2.19 and later Ansible core will preserve types better, but for all other versions templating tends to convert to text.

```auto
   assert:
        that:
          - opt_available_bytes|int > (3 * 1024 * 1024 * 1024)

```

---

<div class="post-metadata">

**Author:** ![tacocat](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@tacocat](https://forum.ansible.com/u/tacocat)\
**Post date:** [July 23, 2025, 8:09pm UTC](https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048/3 "2025-07-23T20:09:58Z")

</div>

I threw a debug statement in to verify what the opt\_available\_bytes variable type was being stored as and even though it’s being passed to | int, it’s being stored as AnsibleUnsafeText:

```auto
TASK [debug] **********************
ok: [localhost] => {
    "msg": "opt_available_bytes type: AnsibleUnsafeText"
}

```

Just wanted to provide that information if it’s of any use.

---

<div class="post-metadata">

**Author:** ![tacocat](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@tacocat](https://forum.ansible.com/u/tacocat)\
**Post date:** [July 23, 2025, 8:11pm UTC](https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048/4 "2025-07-23T20:11:44Z")

</div>

That was it!!! Thank you SO much! Yeah, this box is running v2.17.12.

Thank you again!

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [July 23, 2025, 8:13pm UTC](https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048/5 "2025-07-23T20:13:36Z")

</div>

test case:

```auto
- hosts: localhost
  gather_facts: false
  tasks:
      - set_fact:
          benumber: '{{ 3 * 4}}'

      - debug: msg={{ benumber |type_debug }}

```

Under 2.18:

```auto
PLAY [localhost] *************************************************************************************************************************************************************

TASK [set_fact] **************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *****************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "str"
}

PLAY RECAP *******************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   

```

Under 2.19

```auto
PLAY [localhost] *************************************************************************************************************************************************************

TASK [set_fact] **************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *****************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "int"
}

PLAY RECAP *******************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 22, 2025, 8:13pm UTC](https://forum.ansible.com/t/how-best-to-compare-filesystem-size-against-another-number/44048/6 "2025-08-22T20:13:39Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
