0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

使用 ansible 查看磁盘使用空间 Use ansible to view disk space usage

Last updated at Posted at 2021-06-02
- 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%,运行结果如下:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?