【问题标题】:Ansible stat module directory size output in MiB / GiB. How to convert output?以 MiB / GiB 为单位的 Ansible stat 模块目录大小输出。如何转换输出?
【发布时间】:2021-08-25 13:37:25
【问题描述】:
  - name: check for file size
    stat: 
       path: /apps/InstallDir/data
    register: myDir

  - debug: var=myDir.stat.size

如何获取所需格式 MB 或 GB 的输出并在大于阈值时调试 msg

【问题讨论】:

  • 嗨,Sravan Kumar,欢迎来到 SO。您将需要edit your question 并包含更多细节,最好包括您自己的尝试以及它为您产生的错误。这不是一个代码编写网站,它是为了帮助您对自己的代码进行故障排除,其中与您的问题文本相关的内容很少。祝你好运

标签: ansible filesize


【解决方案1】:

我知道这里的主要问题是:“如何转换,如何输出 MB、MiB、GB 或 GiB,而不是字节?”。

您可以通过使用类似的结构来实现这一点

- name: Check file size
  stat:
    path: "/home/{{ ansible_user }}/testfile"
  register: file_size
  tags: check_fs

- name: Report file size
  debug:
    msg:
      - "{{ ( file_size.stat.size / 1024 / 1024 ) | int }}MiB"
      - "{{ ( file_size.stat.size / 1024 | pow(2) ) | round | int }}MiB"
      - "{{ file_size.stat.size | filesizeformat(True) }}"
      - "{{ file_size.stat.size | filesizeformat }}"
  tags: check_fs

学分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    相关资源
    最近更新 更多