关于ansible:使用-ansible-查看磁盘使用空间

- hosts: 1.1.1.1
  gather_facts: no
  tasks:
    - name: Collect only facts about hardware
      setup:
        gather_subset:
          - 'hardware'

    - name: ensure disk at least 10% free space
      assert:
        that:
          - mount.size_available > mount.size_total|float * 0.1
        fail_msg: "Disk avail: {{(mount.size_available/1000000000.0 )| round(1,'common') }}GB    Disk total: {{(mount.size_total / 1000000000.0) | round(1,'common') }}GB    Disk space is near full!!! "
        success_msg: "Disk avail: {{(mount.size_available/1000000000.0 )| round(1,'common') }}GB    Disk total: {{(mount.size_total / 1000000000.0) | round(1,'common') }}GB"
      vars:
        mount: "{{ ansible_mounts | selectattr('device', 'equalto', '/dev/vdb1') | list | first }}"

# https://gist.github.com/mahemoff/07c0c3427aa3eb3c0abc07f76fc68279
# https://gist.github.com/goodc0re/cbaffab5674cc9324ecb591ab350e564
# https://stackoverflow.com/questions/26981907/using-ansible-to-manage-disk-space

如果磁盘空间有余10%,运行后果如下:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理