Ansible: filter a list by its attributes

To filter a list of dicts you can use the selectattr filter together with the equalto test: network.addresses.private_man | selectattr(“type”, “equalto”, “fixed”) The above requires Jinja2 v2.8 or later (regardless of Ansible version). Ansible also has the tests match and search, which take regular expressions: match will require a complete match in the string, while … Read more

ansible command to list all known hosts

–list-hosts lists hosts that match a –limit. The input is the -i, inventory. Your inventory is a file named hosts, which doesn’t exist. You need to create or generate an inventory file from somewhere. Ansible can’t intuit what your inventory is.