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 }
現在,如果我想編寫一本劇本,我應該如何提及僅顯示掛載點及其可用空間。
我假設您只想顯示此數據而不對其執行任何操作:
--- - 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 輸出中不顯示具有所有屬性的每個項目。