Ansible showing incorrect info when i try to find free space in switch, please help

I have written a script to check for free space in switch before i proceed to copy image. I used ios_facts module and i used below return values however the free and total space displayed is incorrect than the actual free/total space i saw in switch. Why is this happening?

Incorrect value shown for 2960 and 3650 switch but correct value shown when i run the same script in GNS3 router. Even when i convert the bytes/kb shown to MB, it is inccorect.

How to fix this or is there an alternate way to gather freee space and proceed with copying image only if free space is above certain MB?

ansible_net_memfree_mb ansible_net_memtotal_mb ansible_net_filesystems_info

  • name: Gather IOS Facts

    ios_facts: subset: all- debug:

    msg:
    
    - "version is {{ ansible_net_memfree_mb }}"
    
    register: print_output
    
    • name: DISPLAY IF SUFFICIENT SPACE IS THERE OR NOT assert:

      that:

      • ansible_net_memfree_mb >= 14920

      fail_msg: “THERE IS not SUFFICIENT SPACE TO COPY IMAGE”

      success_msg: “THERE IS SUFFICIENT SPACE TO COPY IMAGE”

Nothing prevents you from running a script that returns whatever you want, and use that in the conditional logic in subsequent tasks