Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

size_available in bytes instead kb #1

Open
MrTomtom73 opened this issue Dec 29, 2024 · 0 comments
Open

size_available in bytes instead kb #1

MrTomtom73 opened this issue Dec 29, 2024 · 0 comments

Comments

@MrTomtom73
Copy link

Describe the bug

Could it be that the check of the disc size with the fact size_available is not correct? In my view, the size_available value is returned in bytes instead of kilobytes.

If I define the following variables, I don't get an error even though the free space is too small:

  - name: /
    gigabytes_available: 50

When I query the disc size on the host, I get the following values:

thomas@docker101-lxc:~$ df
Filesystem                         1K-blocks       Used  Available Use% Mounted on
/dev/mapper/pve-vm--101--disk--0    20466256    2234004   17167292  12% /

thomas@docker101-lxc:~$ df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/pve-vm--101--disk--0   20G  2.2G   17G  12% /

thomas@docker101-lxc:~$ df -B1
Filesystem                            1B-blocks          Used     Available Use% Mounted on
/dev/mapper/pve-vm--101--disk--0    20957446144    2287628288   17579298816  12% /

Playbook

I use the following playbook:

---
# file: monitor_diskspace.yml
- name: Monitor Disk Space
  hosts: proxmox_hosts
  become: true
  gather_facts: true
  tags:
    - monitor_diskspace
  collections:
      - robertdebock.roles
  
  roles:
    - diskspace

Output

I receive this issue as verbose:

    "ansible_loop_var": "item",
    "changed": false,
    "item": {
        "block_available": 8386014,
        "block_size": 4096,
        "block_total": 9648476,
        "block_used": 1262462,
        "device": "/dev/mapper/pve-root",
        "dump": 0,
        "fstype": "ext4",
        "inode_available": 2419873,
        "inode_total": 2473984,
        "inode_used": 54111,
        "mount": "/",
        "options": "rw,relatime,errors=remount-ro",
        "passno": 0,
        "size_available": 34349113344,
        "size_total": 39520157696,
        "uuid": "62fa087d-e1c7-4497-b515-59eaafb90eb8"
    },
    "msg": "All assertions passed"
}

Workaround

If I adjust the file mount.yml (lines 20-22) as follows, the check works:

    that:
      - (item.size_available / 1024) | int >= kilobytes_available |int
    fail_msg: "{{ item.mount }} has {{ item.size_available / 1024 }} KB, minimum required {{ kilobytes_available }}."

Output:

failed: [pve1] (item=/) => {
    "ansible_loop_var": "item",
    "assertion": "(item.size_available / 1024) | int >= kilobytes_available |int",
    "changed": false,
    "evaluated_to": false,
    "item": {
        "block_available": 8385967,
        "block_size": 4096,
        "block_total": 9648476,
        "block_used": 1262509,
        "device": "/dev/mapper/pve-root",
        "dump": 0,
        "fstype": "ext4",
        "inode_available": 2419873,
        "inode_total": 2473984,
        "inode_used": 54111,
        "mount": "/",
        "options": "rw,relatime,errors=remount-ro",
        "passno": 0,
        "size_available": 34348920832,
        "size_total": 39520157696,
        "uuid": "62fa087d-e1c7-4497-b515-59eaafb90eb8"
    },
    "msg": "/ has 33543868.0 KB, minimum required 52428800."
}

Environment

  • Control node OS: Debian GNU/Linux 12 (bookworm)
  • Control node Ansible version: 2.17.5
  • Managed node OS: Debian GNU/Linux 12 (bookworm)

Please consider sponsoring me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant