Ansible - 如何在输出中选择元素

Ansible - 如何在输出中选择元素

我是一周前刚开始接触 ansible 的新手。我正在使用剧本和临时命令我运行临时命令 ansible ansiblenodes -m setup -a "filter=ansible_mounts"

192.168.75.31 | SUCCESS => {
    "ansible_facts": {
        "ansible_mounts": [
            {
                "block_available": 217708,
                "block_size": 4096,
                "block_total": 259584,
                "block_used": 41876,
                "device": "/dev/sda1",
                "fstype": "xfs",
                "inode_available": 523952,
                "inode_total": 524288,
                "inode_used": 336,
                "mount": "/boot",
                "options": "rw,seclabel,relatime,attr2,inode64,noquota",
                "size_available": 891731968,
                "size_total": 1063256064,
                "uuid": "8a896a10-d8b0-4c95-9743-69b213b47f5a"
            },
            {
                "block_available": 2145829,
                "block_size": 4096,
                "block_total": 3273216,
                "block_used": 1127387,
                "device": "/dev/mapper/rhel-root",
                "fstype": "xfs",
                "inode_available": 6400742,
                "inode_total": 6551552,
                "inode_used": 150810,
                "mount": "/",
                "options": "rw,seclabel,relatime,attr2,inode64,noquota",
                "size_available": 8789315584,
                "size_total": 13407092736,
                "uuid": "9fe9a7c9-613e-428d-b255-93f0006cf9ad"
            }
        ],
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false
}

现在,如果我想写一本剧本,我应该如何提及仅显示挂载点及其可用空间。

答案1

我假设您只想显示此数据而不对其执行任何操作:

---

- hosts: all
  tasks:
    - name: show filesystems
      debug:
        msg: "mount: {{ item.mount }}, available: {{ item.size_available | human_readable }}"
      loop: "{{ ansible_mounts }}"
      loop_control:
        label: ""

该剧本将显示安装点和可用大小。我使用 Loop_control 不显示 Ansible 输出中具有所有属性的每个项目。

相关内容