如何使用 ad-hoc 命令过滤nocache
块或阻止?我试过了,但没有过滤掉。free
ansible centos1 -m setup -a 'filter=ansible_memory_mb.nocache'
ansible centos1 -m setup -a 'filter=ansible_memory_mb'
centos1 | SUCCESS => {
"ansible_facts": {
"ansible_memory_mb": {
"nocache": {
"free": 11808,
"used": 926
},
"real": {
"free": 10686,
"total": 12734,
"used": 2048
},
"swap": {
"cached": 0,
"free": 4096,
"total": 4096,
"used": 0
}
},
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false
}
答案1
你不能。因为文档setup
说,“过滤选项仅过滤 ansible_facts 下方的第一级子项。”
答案2
这有点混乱,但是你可以......
我正在本地主机上运行 ansible,因此你必须稍微修改一下路径,然后替换本地主机
ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible localhost -m setup | jq .plays[].tasks[].hosts.localhost.ansible_facts.ansible_memory_mb.nocache
输出:
{
"free": 11987,
"used": 703
}