Ansible – Filter Using Ad-hoc Command

ansibleansible-playbook

How can I filter the nocache block or free block using ad-hoc command? I tried ansible centos1 -m setup -a 'filter=ansible_memory_mb.nocache' but doesn't filter it out.

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
}

Best Answer

You can't. As the documentation for setup says, "The filter option filters only the first level subkey below ansible_facts."